Give property name to var type variable returned from a function - CSharp Language Basics

CSharp examples for Language Basics:var

Description

Give property name to var type variable returned from a function

Demo Code

using System;/* w  w w  . java  2s  . co  m*/
class Program
{
   static void Main(string[] args)
   {
      var car = getCar();
      Console.WriteLine($"Model: {car.Model}");
      Console.WriteLine($"Price: {car.Price}");
      Console.WriteLine($"Currency: {car.Currency}");
   }
   private static (string Model, double Price, string Currency) getCar()
   {
      return ("Tesla Model S", 75000, "USD");
   }
}

Result


Related Tutorials