C# Sharp programming Exercises, Practice, Solution : STRUCTURE
C# Sharp STRUCTURE [10 exercises with solution]
1. Write a program in C# Sharp to declare a simple structure. Go to the editor
Expected Output:
Declare a simple structure : -------------------------------- The sum of x and y is 40
2. Write a program in C# Sharp to declare a simple structure and use of static fields inside a structure. Go to the editor
Expected Output :
Structure with the use of static fields inside a structure : --------------------------------------------------------- The sum of x and y is 40
3. Write a program in C# Sharp to create a nested structure to store two data for an employee in an array. Go to the editor
Test Data:
Create a nested structure and store data in an array : ------------------------------------------------------- Name of the employee : H.Rana Input day of the birth : 05 Input month of the birth : 02 Input year for the birth : 58 Name of the employee : S.Mathur Input day of the birth : 04 Input month of the birth : 08 Input year for the birth : 59
4. Write a program in C# Sharp to create a structure and assign the value and call it. Go to the editor
Expected Output:
Create a structure and Assign the Value and call it : --------------------------------------------------------- Assign in Class: x:7500, y:9500 Assign in Structure: x:750, y:950
5. Write a program in C# Sharp to show what happen when a structure and a class instance is passed to a method. Go to the editor
Expected Output:
When a structure and a class instance is passed to a method : -------------------------------------------------------------- ns.n = 5 nc.n = 8
6. Write a program in C# Sharp to declares a structure with a property, a method, and a private field. Go to the editor
Expected Output:
Declares a structure with a property, a method, and a private field : ---------------------------------------------------------------------- The stored value is: 15
7. Write a program in C# Sharp to demonstrates structure initialization using both default and parameterized constructors. Go to the editor
Expected Output:
Structure declares using default and parameterized constructors : ----------------------------------------------------------------- newStruct 1: m = 0, n = 0 newStruct 2: m = 25, n = 25
8. Write a program in C# Sharp to demonstrates structure initialization without using the new operator. Go to the editor
Expected Output :
Structure initialization without using the new operator : -------------------------------------------------------- newStruct : m = 30, n = 40
9. Write a program in C# Sharp to insert the information of two books. Go to the editor
Test Data :
Insert the information of two books : ----------------------------------------- Information of book 1 : Input name of the book : BASIC Input the author : S.TROELSTRA Information of book 2 : Input name of the book : C+ Input the author : G.RTRTG
Expected Output:
1: Title = BASIC, Author = S.TROELSTRA 2: Title = C+, Author = G.RTRTG
10. Write a program in C# Sharp to implement a method that returns a structure including calling the method and using its value. Go to the editor
Test Data :
Method that returns a structure : -------------------------------------- Input the dimensions of the Square( equal length and breadth ) : length : 20 breadth : 40
Expected Output:
Perimeter and Area of the square : Length: 20 Breadth: 40 Perimeter: 120 Area: 800
C# Sharp Code Editor:
More to Come !
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework