---
title: "Struct in C#.Net"  
description: "Astructtype is a value type thatis typically used to encapsulate small groups of related variables, suchas details of student.  Example:Create struct"  
author: "Anonymous User"  
published: 2010-12-30  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/83/struct-in-c-sharp-dot-net  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Struct in C#.Net

A [struct](https://www.mindstick.com/blog/569/difference-between-struct-and-class-in-c-sharp) type is a [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) type thatis typically used to encapsulate small [groups](https://www.mindstick.com/interview/34156/what-are-groups-in-signalr-and-how-can-you-use-them-to-manage-chat-rooms) of related [variables](https://www.mindstick.com/articles/715/php-variables), suchas details of [student](https://www.mindstick.com/articles/157138/student-loan-default-wage-garnishment-and-student-loan).\

##### 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](https://www.mindstick.com/blog/165/generic-class-in-c-sharp).

```
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](https://www.mindstick.com/articles/12918/cat-5e-vs-cat-6a-understanding-the-major-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](https://www.mindstick.com/articles/75377/surprising-benefits-of-learning-to-code) as well.

##### Check these links, for further reading on struct:

http://www.csharp-station.com/tutorials/lesson12.aspx

[http://msdn.microsoft.com/en-us/library/aa288471(v=VS.71).aspx](http://msdn.microsoft.com/en-us/library/aa288471(v=VS.71).aspx)

---

Original Source: https://www.mindstick.com/blog/83/struct-in-c-sharp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
