Create object with var - CSharp Language Basics

CSharp examples for Language Basics:var

Description

Create object with var

Demo Code

using static System.Console;
using System;/*from w  ww  . j  a v  a  2  s  .c  o  m*/
class Program
{
   static void Main(string[] args)
   {
      var p1 = new Person();
      p1.Name = "Back";
      p1.DateOfBirth = new DateTime(2020, 12, 22);
      WriteLine($"{p1.Name} was born on {p1.DateOfBirth:dddd, d MMMM  yyyy}");
   }
}
public class Person : object
{
   public string Name;
   public DateTime DateOfBirth;
}

Result


Related Tutorials