none
how do I pass these value c# RRS feed

  • Question

  • how to do I display the value I set in signup() into seevalue() function. 
    I want the user to be able to set value and see them in seevalue() function.

    namespace MyApp
    {
        class members
        {
            public string name_;
            public int age_;
            public double salary_; 
            public int Age
            {
                get { return age_; }
                set { age_ = value; }
                
            }
            public string Name 
            {
                get { return name_; }
                set { name_ = value; }
            }
            public double Salary
            {
                get { return salary_; }
                set { salary_ = value; }
    
            }
    
            public static void Main(string[] args)
            {
    
                while (true)
                {
                    Console.Clear();
    
                    menu();
    
                    string input = Console.ReadLine();
                    if (input == "1")
                    {
                        Signup();
                    }
                    else if (input == "2")
                    {
                        seeValue();
                    }
                    else if ( input == "3")
                    {
                        Quit();
                    }
                }
            }
    
            public static void menu()
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("sign up: ");
                Console.WriteLine("See members: ");
                Console.WriteLine("Quite: ");
    
            }
            public static int Signup()
            {
                members newMn = new members();
                Console.Write("Whats your name: ");
               
                newMn.name_ = Console.ReadLine();
                Console.Write("Whats your age: ");
                newMn.age_ = Convert.ToInt32(Console.ReadLine());
                Console.Write("Whats yor salary income: ");
                newMn.salary_ = Convert.ToDouble(Console.ReadLine());
                
                
                return 1;
    
            }
    
            public  static void seeValue(members newMn)
            {
                
                Console.WriteLine(newMn);
            }
            static void Quit()
            {
                Environment.Exit(0);
            }


    Thursday, November 29, 2018 6:36 PM

All replies

  • Method seeValue takes one parameter members type. But when you call it in Main function there is not parameter. You can change Signup method to return members type and return newMn object easily.

    namespace MyApp { class members { public string name_; public int age_; public double salary_; public int Age { get { return age_; } set { age_ = value; } } public string Name { get { return name_; } set { name_ = value; } } public double Salary { get { return salary_; } set { salary_ = value; } }

    public override string ToString()

    {

    return string.Format("{0}\t{1}\t{2}", Name, Age, Salary);

    } public static void Main(string[] args) { members signUpResult = null; while (true) { Console.Clear(); menu(); string input = Console.ReadLine(); if (input == "1") { signUpResult = Signup(); } else if (input == "2") { seeValue(signUpResult); } else if ( input == "3") { Quit(); } } } public static void menu() { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("sign up: "); Console.WriteLine("See members: "); Console.WriteLine("Quite: "); } public static members Signup() { members newMn = new members(); Console.Write("Whats your name: "); newMn.name_ = Console.ReadLine(); Console.Write("Whats your age: "); newMn.age_ = Convert.ToInt32(Console.ReadLine()); Console.Write("Whats yor salary income: "); newMn.salary_ = Convert.ToDouble(Console.ReadLine()); return newMn; } public static void seeValue(members newMn) { Console.WriteLine(newMn?.ToString()); } static void Quit() { Environment.Exit(0); }

    }

    }



    Thursday, November 29, 2018 9:00 PM