Structure and Members of the C# Program

CsharpProgrammingServer Side Programming

A structure is a value type data type. It helps you to make a single variable hold related data of various data types. The struct keyword is used for creating a structure.

To define a structure, you must use the struct statement. The struct statement defines a new data type, with more than one member for your program.

For example, here is the way you can declare the Book structure. The following are the members −

struct Books {
   public string title;
   public string author;
   public string subject;
   public int id;
};

To access and display these members in a structure −

Example

using System;

struct Books {
   public string title;
   public string author;
   public int id;
};

public class testStructure {
   public static void Main(string[] args) {
      Books Book1;

      Book1.title = "PHP IN 7 Days";
      Book1.author = "Jacob Dawson";
      Book1.id = 34;

      Console.WriteLine( "Book 1 title : {0}", Book1.title);
      Console.WriteLine("Book 1 author : {0}", Book1.author);
      Console.WriteLine("Book 1 book_id :{0}", Book1.id);

      Console.ReadKey();
   }
}
raja
Published on 14-Aug-2018 17:01:29
Advertisements