Use property in a struct : Properties « struct « C# / CSharp Tutorial






using System;

public struct Square
{
   public int Width
   {
      get
      {
         return width;
      }

      set
      {
         width = value;
      }
   }

   public int Height
   {
      get
      {
         return height;
      }

      set
      {
         height = value;
      }
   }
   
   private int width;
   private int height;
}

public class MainClass
{
   static void Main()
   {
      Square sq = new Square();
      sq.Width = 1;
      sq.Height = 1;
   }
}








6.6.Properties
6.6.1.Use property in a struct
6.6.2.Accessing Structures with Properties and Public Members