Return more than one value from a function - CSharp Language Basics

CSharp examples for Language Basics:Tuple

Description

Return more than one value from a function

Demo Code

using System;//from ww w  .ja  v a 2 s .c om
class Program
{
   static void Main(string[] args)
   {
      (string model, double price, string currency) = getCar();
      Console.WriteLine($"Model: {model}");
      Console.WriteLine($"Price: {price}");
      Console.WriteLine($"Currency: {currency}");
      Console.ReadKey();
   }
   private static (string Model, double Price, string Currency) getCar()
   {
      return ("Tesla Model S", 75000, "USD");
   }
}

Result


Related Tutorials