The structure is a value type data type. It helps you make a single variable hold related data of various data types. The struct keyword is used to create structures.
To define a structure, you must use the struct statement. The struct statement defines a new data type that provides multiple members to your program.
For example, you can declare a Book structure in the following way. Following are the members -
struct Books { public string title; public string author; public string subject; public int id; };
Access and display these members in the structure -
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(); } }
The above is the detailed content of C# program structures and members. For more information, please follow other related articles on the PHP Chinese website!