Adv C#
Programming

1. Introduction to .NET and C# 2. Points to keep in mind for pyramid 3. C# Pyramid Program Example for type 1 4. C# Pyramid Program Example for type 2 5. C# Pyramid Programs on Type 3 6. C# Pyramid Programs of type 4 7. C# Pyramid Programs of type 5 8. Classes and Objects 9. Recursive functions 10. Constructors in C# 11. Destructor 12. Method Overloading 13. Constructor Overloading 14. Inheritance in C# 15. Interface in C# 16. Method Overriding 17. readonly and sealed keyword in C# 18. Exception Handling 19. Delegates 20. Multicast Delegates 21. Events 22. Structure 23. Threads 24. Working with Threads 25. Thread Life Cycle 26. Introducing Multithreading 27. Advantage and limitation of multithreading 28. Thread priority 29. Properties 30. Collections 31. ArrayList Class 32. Hastable Class 33. SortedList 34. Stack 35. Queue Class 36. Generics 37. Unsafe code 38. C# Networking 39. Prgs for Science and Engineer 40. Prg to use alias 41. Prg to count minors and majors using array 42. Prg for sum up of two array in third array 43. Prg to show boxing and unboxing 44. Prg for type casting from byte to int 45. Prg to find area of circle 46. Prg to find cube root of entered number 47. Prg for digit manipulation 48. Prg for printing a reverse triangle 49. Prg to show case and goto fall through 50. Prg to show use of foreach loop 51. Prg for adding 2 numbers 52. Prg to show jagged array 53. Prg to show different methods of Array 54. Prg to print number Pyramid 55. Prg to show entered string is palindrome or not 56. Prg to show entered number is prime or not 57. Prg to show different methods of StringBuilder 58. Prg to show different methods of String 59. Prg for appending a string using StringBuilder 60. Prg to show appending a string with numeric type data using StringBuilder 61. Prg to show use of ArrayList 62. Prg to pass an array as a parameter to a function for finding out a prime number 63. Prg to show the constant member 64. Prg for showing destructor 65. Prg for sum up and reversing the entered number 66. Prg for enum type conversation 67. Prg to show sum of first fifty even and odd number 68. Prg to find the factorial of entered number 69. Prg for iterating each element of array using foreach loop 70. Prg to show array position and value 71. Prg to show how to insert and remove string using StringBuilder 72. Prg to show how to join the string 73. Prg to show the value of sin 90 74. Prg to enter two number and find max 75. Prg to show padding 76. Prg to show entered number is prime or not 77. Prg to show private constructor 78. Prg to show how to use getter and setter property 79. Prg using out parameter 80. Prg to count the number of spaces and words in a String 81. Prg to show how to use Split method 82. Prg to create binary triangle 83. Prg to create dule star triangle 84. Prg to create triangle 85. Prg to show use of EndsWith and StartsWith method of string 86. Prg for static constructor 87. Prg to show how to use insert method 88. Prg to sort a string 89. Prg to store student name and roll no using structure 90. Prg to show how to use delegate 91. Prg to calculate depreciation 92. Prg for calculating Economic order cost and time between order 93. Prg to find radius of circle 94. Prg to sum up odd numbers from 0 to 20 95. Prg to calculate simple interest 96. Prg to categorise student on base of there marks range where marks are stored in array 97. Prg to create triangle on console screen 98. Prg to print sin theta, cos theta and tan theta from 0.1 to 1.0 angle in radians 99. Prg to demonstrate variables 100. Prg to illustrate the differences between int and double 101. Prg to show exception handling using try.. catch block 102. Prg to demonstrate how to use interface 103. Prg to print number triangle 104. Prg to demonstrate structure 105. Prg to test exception 106. Prg to count number of spaces and words in a entered string 107. Prg to demonstrate ref parameter 108. Prg to print a matrix table from 1 to 10 109. Prg to display 2 D array elements position in matrix form 110. Prg to count number of adult and children 111. Prg to print pascal triangle 112. Prg to demonstrate stringbuilder and its method 113. Prg to reverse a string 114. Prg for string sorting 115. Interview Question & Answer part 1 116. Interview Question & Answer part 2 117. Interview Question & Answer part 3 118. Interview Question & Answer part 4 119. Interview Question & Answer part 5 120. Interview Question & Answer part 6 121. Interview Question & Answer part 7 122. Interview Question & Answer part 8 123. Interview Question & Answer part 9 124. Interview Question & Answer part 10 125. Interview Question & Answer part 11 126. Interview Question & Answer part 12 127. Interview Question & Answer part 13 128. Interview Question & Answer part 14 129. Interview Question & Answer part 15
Pr.Pg Next Pg

Structure tutorials

  • In C#, a structure is a value type data type. It helps you to make a single variable hold related data of various data types.

  • The struct keyword is used for creating a structure. Structures are used to represent a record.

 

Features of structure

  • Structures in C# are quite different from that in traditional C or C++. The C# structures have the following features:

  • Structures can have methods, fields, indexers, properties, operator methods, and events.

  • Structures can have defined constructors, but not destructors. However, you cannot define a default constructor for a structure. The default constructor is automatically defined and can be changed.

  • Unlike classes, structures cannot inherit other structures or classes.

  • Structures cannot be used as a base for other structures or classes.

  • A structure can implement one or more interfaces.

  • Structure members cannot be specified as abstract, virtual, or protected.

  • When you create a struct object using the New operator, it gets created and the appropriate constructor is called. Unlike classes, structs can be instantiated without using the New operator.

  • If the New operator is not used, the fields will remain unassigned and the object cannot be used until all the fields are initialized.

  • Suppose you want to keep track of student. You might want to track the following attributes about each student:

rollno

name

percent

 

  • To define a structure, you must use the struct statement. The struct statement defines a new data type, with more than one member for your program.

  • For example, here is the way you would declare the student structure:

struct student

{

public int rollno;

public string name;

public float percent;

};

 

 

Example: Csharp program to demonstrate declaring and initializing structure variables

Sam Madam 

// Csharp program to demonstrate declaring and initializing structure variables

using System;

struct student

{

public int rollno;

public string name;

public float percent;

};

class Program

{

static void Main()

{

student s1,s2,s3,s4;

//Declaring and initializing s1 and s4 variables

s1.rollno=101;

s1.name="SAM";

s1.percent=80.75f;

s4.rollno=104;

s4.name="John";

s4.percent=75.00f;

//End of declaration

Console.Write("Enter Roll no of student :");

s2.rollno = Int32.Parse(Console.ReadLine());

Console.Write("Enter name of student :");

s2.name = Console.ReadLine();

Console.Write("Enter Percentage :");

s2.percent = float.Parse(Console.ReadLine());

s3 = s2; // copy s2 into s3

Console.WriteLine(s1.rollno+" "+s1.name+" "+s1.percent);

Console.WriteLine(s2.rollno+" "+s2.name+" "+s2.percent);

Console.WriteLine(s3.rollno+" "+s3.name+" "+s3.percent);

Console.WriteLine(s4.rollno+" "+s4.name+" "+s4.percent);

}

}

 

Output

Enter Roll no of student :102

Enter name of student :sush

Enter Percentage :98.5

101 SAM 80.75

102 sush 98.5

102 sush 98.5

104 John 75


 

Example: Csharp program to create a structure to accept a complex number in the form of x+iy and print it

Sam Madam 

// Csharp program to create a structure to accept a complex number in the form of x+iy and print it

using System;

struct complex

{

public float real, imag;

};

class Program

{

static void Main()

{

complex c1, c2;

Console.Write("Enter the real part for the first complex number: ");

c1.real = float.Parse(Console.ReadLine());

Console.Write("Enter the imaginary part for the first complex number: ");

c1.imag = float.Parse(Console.ReadLine());

Console.Write("Enter the real part for the second complex number: ");

c2.real=float.Parse(Console.ReadLine());

Console.Write("Enter the imaginary part for the second complex number: ");

c2.imag=float.Parse(Console.ReadLine());

Console.WriteLine("First complex number: "+c1.real +" + i"+ c1.imag);

Console.WriteLine("Second complex number: "+c2.real +" + i"+ c2.imag);

}

}

 

Output

Enter the real part for the first complex number: 2

Enter the imaginary part for the first complex number: 3

Enter the real part for the second complex number: 4.5

Enter the imaginary part for the second complex number: 13

First complex number: 2 + i3

Second complex number: 4.5 + i13

Pr.Pg border                                              Next Pg