Use var to create object and access its member - CSharp Language Basics

CSharp examples for Language Basics:var

Description

Use var to create object and access its member

Demo Code

using static System.Console;
using System;/*from   www  .j a v  a  2  s . co  m*/
using System.Collections.Generic;
using System.Text.RegularExpressions;
class Program
{
   static void Main(string[] args)
   {
      var t = new Thing();
      t.Data = 42;
      WriteLine($"Thing: {t.Process("42")}");
   }
}
public class Thing
{
   public object Data;
   public string Process(string input)
   {
      if (Data == input)
      {
         return Data.ToString() + Data.ToString();
      }
      else
      {
         return Data.ToString();
      }
   }
}

Related Tutorials