A struct type is a value type thatis typically used to encapsulate small groups of related variables, suchas details of student.

Example:Create struct
    public structStudentDetails
        /// <summary>
        /// ID of student
        /// </summary>
        public string StudentID;
        /// <summary>
        /// Name of student
        /// </summary>
        public string Name;
        /// <summary>
        /// Father’s name of student
        /// </summary>
        public string FatherName;
        /// <summary>
        /// Address of student
        /// </summary>
        public string Address;


Example: Using struct

To use a struct,instantiate the struct and use it just like a class.

StudentDetails sd = new StudentDetails;
sd.studentID= "324";
sd.Name= "XYZ";
sd.FatherName= "ABC";
sd.Address= "California, USA";

Difference between struct and class

Structs may seem similar to classes, but there areimportant differences that you should be aware of. First of all, classes arereference types and structs are value types. By using structs, you can createobjects that behave like the built-in types and enjoy their benefits as well.

Check these links, for further reading on struct:



  Modified On Sep-18-2014 01:23:53 PM
  1. Thanks for sharing informative post.

    Your words increase my knowledge for sure. Thanks

Leave Comment