Jump to content

function help,

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
Hello,

Right now i am learning about functions, i just have a question, i have the code below as an example of just passing a varaible (string) from one function to another, however just using a return and not declaring in the parameter. my question is what happens when you want to pass more than 1 variable from one function to another? i have the code below just to take a look at what i am doing but please let me know any suggestions, information and examples. Thank you in advance


class Program

        {

            

            

            static string write()

            {

                

                string mystring;

                Console.WriteLine("Please enter first name");

                mystring = Console.ReadLine();

                return mystring;

                

            }

            

            

            static void Main(string[] args)

            

            {

                string stringer, stringer2;

                stringer = write();

                Console.WriteLine("Please Enter Last Name");

                stringer2 = Console.ReadLine();

                Console.WriteLine("Hello " + stringer + " " + stringer2);

                Console.ReadKey();

                



}




#2
gamiR

gamiR

    Learning Programmer

  • Members
  • PipPipPip
  • 96 posts
If you want to return more than 1 variable it is not simple. You have to declare that variable as pointer to make changes to variables and no need to pass them.
Busy Penguin

#3
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
Thanks Gamir but can you give me an example or someone give me an example?

#4
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
class Program
        {
            
            
            static string write(string type)
            {
                
                string mystring;
                Console.WriteLine("Please enter " + type + " name");
                mystring = Console.ReadLine();
                return mystring;
                
            }
            
            
            static void Main(string[] args)
            
            {
                Console.WriteLine("Hello " + write("first") + " " + write("middle") + " " + write("last");
                Console.ReadKey();
                


}

Tada.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums