我该怎么做才能在C#Console中实现Mvp? [英] What Should I Do To Implement Mvp In C# Console?

查看:86
本文介绍了我该怎么做才能在C#Console中实现Mvp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 命名空间 ConsoleApplication2 
{

class 程序
{
静态 void Main( string [] args)
{
// 我该如何在这里打印列表学生?
}
}
class 学生
{
public int ID { get ; set ; }
public string FirstName { get ; set ; }
public string LastName { get ; set ; }
public string Class { get ; set ; }
public string 专业{ get ; set ; }
}
class ListItemhelper
{
public static IEnumerable< Student> GetListItemData( int id)
{
return 列表< Student>
{
{学生{Id = 1 ,LastName = a,FirstName = A,Major = IT,Class = < span class =code-string>
10dthh}},
{ new 学生{Id = 2 ,LastName = b,FirstName = B,Major = IT,Class = 10dth}}
};
}
}
class ListStudentPresenter
{
private IStudentList学生;
public ListStudentPresenter(IStudentList student)
{
this .student =学生;
}
public void LoadListItem( int id)
{
IEnumerable< Student> stus = ListItemhelper.GetListItemData(id);
if (stus!= null && stus.Any())
{
student.Istudent = stus;
}
else
{
student.MessageError = 找不到任何项目;
}
// view.LoadData();
}
}
public interface IStudentList {
IEnumerable< Student> Istudent { get ; set ;}
string MessageError { get ; set ; }
}
}



我正在尝试实现MVP控制台环境。那么现在我想在屏幕上显示学生名单,但我不知道如何。请帮助我!!!

解决方案

请看这里: http://stackoverflow.com/questions/1445094/how-to-implement-mvp-in-console-application [ ^ ]


请参阅我对这个问题的评论。



我有一种强烈的印象,你不知道你在说什么,也不知道MVP是什么。怎么称它为MVP控制台环境?最有可能的是,这是关于这种架构模式:

https ://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter [ ^ ],

https://en.wikipedia.org/wiki/Architectural_pattern [ ^ ]。



在标题下面的问题中,没有模型,视图或控制器的痕迹关于如何显示某些列表的问题。你是什​​么意思当然,为每个列表元素使用 System.Console.Write System.Console.WriteLine



更重要的是,我不确定你是否理解任何建筑模式都不是你的目标。这可能会或可能不会有助于实现项目,工具的目标,而不是目标。



-SA

namespace ConsoleApplication2
{

    class Program
    {
        static void Main(string[] args)
        {
            //What should i do to print list student at here?
        }
    }
     class Student
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Class { get; set; }
        public string Major { get; set; }
    }
     class ListItemhelper
    {
        public static IEnumerable<Student> GetListItemData(int id)
        {
            return new List<Student>
            {
                {new Student{Id=1,LastName="a",FirstName="A",Major="IT",Class="10dthh"}},
                {new Student{Id=2,LastName="b",FirstName="B",Major="IT",Class="10dthh"}}
            };
        }
    }
     class ListStudentPresenter
    {
        private IStudentList student;
        public ListStudentPresenter(IStudentList student)
        {
            this.student = student;
        }
        public void LoadListItem(int id)
        {
            IEnumerable<Student> stus = ListItemhelper.GetListItemData(id);
            if (stus != null && stus.Any())
            {
                student.Istudent = stus;
            }
            else
            {
                student.MessageError = "No items found";
            }
            //view.LoadData();
        }
    }
    public interface IStudentList{
        IEnumerable<Student> Istudent {get;set;}
        string MessageError { get; set; }
      }
}


I'm trying to implement MVP console environment. Then now I wanna display List of students in view to screen but i don't know how. Please help me !!!

解决方案

See here: http://stackoverflow.com/questions/1445094/how-to-implement-mvp-in-console-application[^]


Please see my comment to the question.

I have a strong impression that you don't know what you are talking about and don't know what MVP is. How it can be called "MVP console environment"? Most likely, it's about this architectural pattern:
https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter[^],
https://en.wikipedia.org/wiki/Architectural_pattern[^].

In the question below your title, there is no trace of model, or view, or controller, only a question on how to display some list. What do you mean how. By using System.Console.Write of System.Console.WriteLine for each list element, of course.

More importantly, I'm not sure you understand that any architectural pattern hardly can be your goal. This is something which may or may not help reaching the goals of your project, tool, not a target.

—SA


这篇关于我该怎么做才能在C#Console中实现Mvp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆