无法将用户输入转移到控制台应用程序中的另一种方法?? [英] cannot transfer user input to another method in console application??

查看:87
本文介绍了无法将用户输入转移到控制台应用程序中的另一种方法??的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public static void add(employee em)
        {
            string name;
            Console.WriteLine("Enter Name");
            name = Console.ReadLine();
            
            Console.WriteLine("Enter Sex");
            string sex = Console.ReadLine();
            
            Console.WriteLine("employee saved");
            Console.ReadKey();
            
        }
        public static void show(employee em)
        {
           
            Console.WriteLine("Name:{0}",???);
            Console.WriteLine("Sex:{0}", ???);
            Console.ReadKey();
        }





how can i use the value entered by user in add method to display in show method.what do i need to write in main function too to run both??

推荐答案

您应该重新阅读有关使用类和对象的教程.您的employee类应包含对象的属性(名称,年龄,性别,...),并在适当时使用setter和getter.然后,您的主程序应使用控制台获取各种详细信息,并每次创建一个新对象.您应该将所有对象放在适当的容器中,例如List.您还需要某种方式将对象持久保存到永久存储中,以备将来参考.
You should revisit your tutorials on the use of classes and objects. Your employee class should hold the properties of the object(name, age, sex, ...), and use setters and getters as appropriate. Your main program should then use the console to get the various details and create a new object each time. You should hold all your objects in an appropriate container, such as a List. You will also need some way of persisting your objects to permanent storage, for future reference.


这篇关于无法将用户输入转移到控制台应用程序中的另一种方法??的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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