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,907 questions

51,839 answers

573 users

How to return multiple values from a method in C#

3 Answers

0 votes
using System;
 
class Program
{
    static void Method(out int n, out string s, out float f) {
        n = 847;
        s = "C# programming";
        f = 459.234f;
    }
    static void Main()
    {
        int n;
        string s;
        float f;
         
        Method(out n, out s, out f);
         
        Console.WriteLine(n);
        Console.WriteLine(s);
        Console.WriteLine(f);
    }
}
 
 
 
/*
run
 
847
C# programming
459.234
 
*/

 



answered Feb 18, 2017 by avibootz
edited Apr 24, 2024 by avibootz
0 votes
using System;
using System.Collections.Generic;

class Program
{
    static KeyValuePair<int, int> GetNumbers() {
        return new KeyValuePair<int, int>((int)Math.Pow(2, 3),
                                              (int)Math.Pow(2, 5));
    }
    
    public static void Main(string[] args)
    {
        var keyvalue = GetNumbers();
 
        Console.WriteLine(keyvalue.Key);
        Console.WriteLine(keyvalue.Value);
    }
}


 
/*
run:
      
8
32
  
*/

 



answered Feb 18, 2017 by avibootz
edited Apr 24, 2024 by avibootz
0 votes
using System;
 
class Program
{
    static Tuple<int, int, int> m() { 
        int a = 34, b = 982, c = 5; 
 
        return Tuple.Create(a, b, c);
    } 
     
    static void Main() {
        var result = m(); 
         
        Console.WriteLine("{0}, {1}, {2}", result.Item1, result.Item2, result.Item3);
    }
}
 
 
 
/*
run:
 
34, 982, 5
 
*/

 



answered Apr 24, 2024 by avibootz

Related questions

1 answer 126 views
2 answers 191 views
3 answers 215 views
1 answer 61 views
1 answer 144 views
1 answer 153 views
1 answer 126 views
126 views asked Jan 2, 2022 by avibootz
...