Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
C#
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??
Posted
Updated 1-Mar-10 23:14pm
v3

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900