Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Declare a simple structure

C# Sharp STRUCTURE: Exercise-1 with Solution

Write a program in C# Sharp to declare a simple structure.

Sample Solution:-

C# Sharp Code:

using System;
struct w3rStruct
{
    public int x;
    public int y;
}
class strucExer1
    {
    public static void Main()
        {
        Console.Write("\n\nDeclare a simple structure :\n");
        Console.Write("--------------------------------\n"); 	
        w3rStruct w3st = new w3rStruct();
        w3st.x = 15;
        w3st.y = 25;
        int sum = w3st.x + w3st.y;
        Console.WriteLine("The sum of x and y is {0}\n",sum);
        }
    }

Sample Output:

Declare a simple structure :                                                                                  
--------------------------------                                                                              
The sum of x and y is 40

Flowchart:

Flowchart: Declare a simple structure.

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: C# Sharp STRUCTURE Exercises with solution.
Next: Write a program in C# Sharp to declare a simple structure and use of static fields inside a struct.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.