Structure (C#)

structure-csharp
In this chapter you will learn:

  • What is structure in C#?
  • How to create user defined data types using structure?
  • How to implement structure in C# programming?

Structure is the value type data type that can contain variables, methods, properties, events and so on. It simplifies the program and enhance performance of code in C# programming.

The structure encapsulate small group of related variables inside a single user-defined data type. It improves speed and memory usage and also enhances performance and clarity of your code.

How to use structure in C#?

It is very simple to use structure in C#. The following programming example will show you to how to create and use structure in C# programming.


Programming Example of Structure (C#)

Output

Enter book name :         C Sharp
Enter book price :         34
Enter book category :    Object Oriented ProgrammingEnter book name :         SQL Server
Enter book price :         23
Enter book category :    Database Programming=============================================
Language
=============================================Enter book name :         C Sharp
Enter book price :         34
Enter book category :    Object Oriented Programming

=============================================
Database
=============================================

Enter book name :         SQL Server
Enter book price :         23
Enter book category :    Database Programming
__

In the preceding example, we create a structure named book that contain three variables as bookname, price, category. These variables can be accessed by creating the object of book structure.

Next, we create two variables of book as language and database. Then store the value in language and database and display the value on console.

Summary

In this chapter you learned what structure is and how to use it in C# programming. In next chapter you will get some programming examples.



Leave a Reply

Your email address will not be published. Required fields are marked *