Struct in C#

How to use Struct in C#.

Note:-   Struct are Value type similar to Enum.  It is use to represent the record.

Ex:-   Creating Struct for Vehicle.

Program

using System;
using System.Text;


namespace Test_Application
 {

    struct Vehicle
    {
        public string Four_Wheeler;
        public string Two_Wheeler;
        public string Three_Wheeler;
    }
    class Program
     {
        public static void Transportation()
        {
            var trans = new Vehicle();
            trans.Four_Wheeler = "Car";
            trans.Three_Wheeler = "Auto Rickshaw";
            trans.Two_Wheeler = "Cycle, Bikes";

            Console.WriteLine(trans.Four_Wheeler);
            Console.WriteLine(trans.Three_Wheeler);
            Console.WriteLine(trans.Four_Wheeler);
        }
         public static void Main(string[] args)
         {
            Transportation();
            Console.ReadLine();
        }
    }
 }

Output:- Car
               Auto Rickshaw
               Cycle, Bikes
    





Share this

Previous
Next Post »