Thursday, 2020-10-22, 12:14 PM
Welcome Guest | RSS
Site menu
Tag Board
Our poll
How do you rate .Net classes ?
Total of answers: 207

Total online: 1
Guests: 1
Users: 0


Structure: To define a structure we have to use "struct" keyword.

Structure is a collection of members, it can contain variables, properties, methods, constructors, events, indexers, but it can not contain destructors.

Structure can contain constructor which are parameter less constructor which are parameter less constructor, that means structure cannot contain parametrized constructor.

Structure is value type which are stack based data types that means when we create an object for structure it will be allocating into stack memory.

Syntax to define a structure:
     <accessmodifier> struct <structure name>
       // structure members

To create an object for structure we don't require to use new operator.

Syntax to create an object for structure:
    <structure name> <object name>;

Structures will not support inheritance, due to that reason access modifier of a structure or structure member cannot be protected or protected internal.

In C#.NET we cannot have abstract structure and sealed structure.

namespace structureexample
  Public struct mystruct
      Public int i;
      Public void mymethod()
           Console.WriteLine("My method is calling");

   Class mainclass
      Void main()
          //creating object for structure
          mystruct structobj;
          structobj.i = 10;
         Console.WriteLine("i value is " +structobj.i)
Output: i value is 10
             mymethod is calling

Difference between class & structure:

Constant: Constant can be called as a field, it is a member of a class.

Constant is representing a fixed value with a user defined name.

Constant value should be initialized at the time of declaration i.e., we are initializing in design time which cannot be changed in run time.

By default constants are static members due to that reason we have to access with the help of class name.

Eg: for constant:

namespace company
   Public class Employee
       Public const int minimumworkhours = 9;

   Class mainclass
      void main()
           Console.WriteLine("Every employee minimum working hours per day is " +Employee.minimumworkinghours);
Output: Every employee minimum working hours per day is 9




«  October 2020  »


Entries archive

Copyright R N Reddy © 2020Developed by Nagendra, Venkat, Vijaya and Yaswanth
Get free updates as SMS to your mobile. Just register by clicking here