w3resource
C# Sharp Programming Exercises

C# Sharp Exercises: Structure with use of static fields inside a struct

C# Sharp STRUCTURE: Exercise-2 with Solution

Write a program in C# Sharp to declare a simple structure and use of static fields inside a struct.

Sample Solution:-

C# Sharp Code:

using System;

struct w3rStruct
{
public static int x = 15;
public static int y = 25;
}
class strucExer2
    {
    public static void Main()
        {
        Console.Write("\n\nStructure with the use of static fields inside a struct :\n");
        Console.Write("-------------------------------------------------------------\n"); 	
        int sum = w3rStruct.x + w3rStruct.y;
        Console.WriteLine("The sum of x and y is {0}\n",sum);
        }
    }

Sample Output:

Structure with the use of static fields inside a struct :                                                     
-------------------------------------------------------------                                                 
The sum of x and y is 40

Flowchart:

Flowchart: Structure with use of static fields inside a struct

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C# Sharp to declare a simple structure.
Next: Write a program in C# Sharp to create a nested struct to store two data for an employee in an array.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming