Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,990 questions

51,935 answers

573 users

How to use out to return more then on value from a function in C#

1 Answer

0 votes
using System;

namespace functions_out
{
	class Class1
	{
		static void Main(string[] args)
		{
			int x = 5, y = 10, z = 15;

            Console.WriteLine("befor x = {0}, y = {1}, z = {2}", x, y, z);
            // befor x = 5, y = 10, z = 15
            f(x, out y, out z);
			Console.WriteLine("after x = {0}, y = {1}, z = {2}", x, y, z);
            // after x = 5, y = 105, z = 405

            y = f(out x,  y, out z);
            Console.WriteLine("x = {0}, y = {1}, z = {2}", x, y, z);
            // x = 1, y = 2, z = 3
		}
		static void f(int x, out int y, out int z)
		{
			y = x + 100;
			z = x + 400;

            x = 1000;
		}
        static int f(out int x, int y, out int z)
        {
            x = 1;
            y = 2;
            z = 3;

            return y;
        }
	}
}



answered Jul 30, 2014 by avibootz

Related questions

...