Create and use Automatic properties in CSharp

Description

The following code shows how to create and use Automatic properties.

Example


     //from w ww. j a  va  2  s .  com
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass{

   public static void Main(string[] args){   
      MyName2 n = new MyName2();
      n.FirstName = "J";
      Console.WriteLine(n.FirstName);
   }
}


   public class MyName2
   {
      public String FirstName
      {
         get;
         set;
      }

      public String LastName
      {
         get;
         set;
      }
   }

The code above generates the following result.





















Home »
  C# Tutorial »
    Custom Types »




C# Class
C# Struct
C# Interface
C# Inheritance
C# Namespace
C# Object
C# Delegate
C# Lambda
C# Event
C# Enum
C# Attribute
C# Generics
C# Preprocessor