C# Program to Demonstrate the Static Constructor in Structure Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report A Structure is a well-defined data structure that can hold elements of multiple data types. It is similar to a class because both are user-defined data types and both contain a bunch of different data types. You can also use pre-defined data types. However, sometimes the user might be in need to define its own data types which are also known as User-Defined Data Types. A structure can also hold constructors, constants, fields, methods, properties, and indexers, etc. We can create a structure by using the struct keyword followed by the name of the structure. Syntax: public struct structure_name { // Body of the structure } A Static constructor is a type of constructor that is called before the first instance of the structure or class gets created. It is initialized with static fields or data of the structure and is to be executed only once. We can create a static constructor by using static keyword and followed by constructor name. Syntax: static class() { // Body of the static constructor } Given a structure, now our task is to use a static constructor in the given structure. So to this, we have to follow the following approach. Approach Create a structure named GFG.Create a static constructor with no parameters inside the structure.public struct class { static class() { // Constructor body } }Create a non-static method named GFG by passing an integer parameter to it.Assign the variable to call the non static constructor in a separate method inside the structure.In the main method, create an object for the structure and access the both static and non static methods by creating the object.Example: C# // C# program to illustrate how to use the // static constructor in the structure using System; // Create a structure public struct GFG { // Static method names GFG static GFG() { Console.WriteLine("Hello! Static constructor is called"); } // Non static method public GFG(int variable) { Console.WriteLine("Hello! Non-Static constructor is called"); } } // Driver code class Geeks{ static void Main(string[] args) { // Create the object for // the structure GFG obj = new GFG(2); } } Output: Hello ! Static constructor is called Non-Static constructor is called Comment More infoAdvertise with us Next Article How to Define the Constructor Outside the Class in C++? S sravankumar_171fa07058 Follow Improve Article Tags : C# CSharp-programs Similar Reads C# Program to Demonstrate the Array of Structures An array of structures means each array index contains structure as a value. In this article, we will create the array of structure and access structure members using an array with a specific index. Syntax array[index].Structure(Details); where index specifies the particular position to be inserted 2 min read How to Define the Constructor Outside the Class in C++? A constructor is a special type of member function whose task is to initialize the objects of its class. It has no return type so can't use the return keyword and it is implicitly invoked when the object is created. Constructor is also used to solve the problem of initialization. It is called after 2 min read C# Program to Implement an Interface in a Structure Structure is a value type and a collection of variables of different data types under a single unit. It is almost similar to a class because both are user-defined data types and both hold a bunch of different data types. We can create a structure by using struct keyword. A structure can also hold co 2 min read C# | Difference between Static Constructors and Non-Static Constructors Prerequisite: Constructors in C# Static constructors are used to initialize the static members of the class and are implicitly called before the creation of the first instance of the class. Non-static constructors are used to initialize the non-static members of the class. Below are the differences 6 min read How to access structure elements using Pointers in C# Unlike C/C++, Structures in C# can have members that are methods, fields, indexers, operator methods, properties or events. The members can have access specifiers as public, private, and internal. Pointers are variables that store the addresses of the same type of variable i.e. an int pointer can st 3 min read Private Constructors in C# Prerequisite: Constructors in C# Private Constructor is a special instance constructor present in C# language. Basically, private constructors are used in class that contains only static members. The private constructor is always declared by using a private keyword. Key PointsIt is the implementatio 3 min read Like