11
Reply

What are the Difference between Structure and Class??

Abhishek Yadav

Abhishek Yadav

Jul 27, 2014
2k
1

    1. Class are ref type and Struc are value type 2. Struc doesn't support inheritance except interface. 3. Class use heap and Struc use Stacks 4 Class use concept of boxing and unboxing but Struc doesn't use 5. members of struc are by default public where as in class members are private. 6. we can not create default constructor of struc

    1:-Strucuter is a value type and class is a reference type 2:-Classes will support an Inheritance whereas Structures won't 3:-Classes can have explicitly parameterless constructors whereas structures can't. 4:-Member variable initialization is possible in class whereas in Structures, it is not. 5:The “this” keyword gives different meaning in structure and class. How? In class, “this” keyword is classified as value type of class type within which it is used like inside instance constructor or instance method. In structure, “this” keyword is classified as variable type of structure type within which it is used.

    Abrar Ahmad Ansari
    March 10, 2015
    1

    1)Class use for representing entities with larger volume of data, Structure use for representing entities with Smaller volume of data. 2)In Class :- Memory is allocated on Managed Heap so automatic memory management is possible thru Garbage Collector, In Structure :- Store on Stack memory so automatic memory management is not possible thru Garbage Collector but "Faster in access.

    Sandeep Singh
    September 05, 2016
    0

    Private constructors are used to prevent creating instances of a class when there are no instance fields or methods, such as the Math class, or when a method is called to obtain an instance of a class. If all the methods in the class are static, consider making the complete class static.

    Ajay Gandhi
    November 20, 2015
    0

    Structure for value type and class for reference type Structure stored in stack and class stored in the heap

    Yatendra Sharma
    July 08, 2015
    0

    This example help you difference between Class and Struct Analise out put of this console Application class A{private string _Height;private string _Weight;public string Height{get{return _Height;}set{_Height = value;}}public string Weight{get{return _Weight;}set{_Weight = value;}}}struct B{private string _Height;private string _Weight;public string Height{get{return _Height;}set{_Height = value;}}public string Weight{get{return _Weight;}set{_Weight = value;}}}class Test1{static void Main(string[] args){A objAOne = new A();Console.WriteLine("Property Height " + objAOne.Height + "Weight " + objAOne.Weight);objAOne.Height = "1";objAOne.Weight = "1";Console.WriteLine("Property Height " + objAOne.Height + "Weight " + objAOne.Weight);//obj.ChangeProperty();Console.WriteLine("Property Height " + objAOne.Height + "Weight " + objAOne.Weight);Console.WriteLine("----------------------Assign Value to Another objcet 'ObjSecond'-----------------------------------");A obASecond = objAOne;Console.WriteLine("----------------------Assign Value to objcet 'ObjSecond' 3 & 3-----------------------------------");obASecond.Height = "3";obASecond.Weight = "3";Console.WriteLine("----------------------Call to First object-----------------------------------");Console.WriteLine("Property Height " + objAOne.Height + "Weight " + objAOne.Weight);Console.WriteLine("----------------------Call to Second object-----------------------------------");Console.WriteLine("Property Height " + obASecond.Height + "Weight " + obASecond.Weight);Console.WriteLine("-------------------------Struct---------------------------------------");B objBOne = new B();Console.WriteLine("Property Height " + objBOne.Height + "Weight " + objBOne.Weight);objBOne.Height = "1";objBOne.Weight = "1";Console.WriteLine("Property Height " + objBOne.Height + "Weight " + objBOne.Weight);// objB.ChangeProperty();Console.WriteLine("Property Height " + objBOne.Height + "Weight " + objBOne.Weight);Console.WriteLine("----------------------Assign to Second object-----------------------------------");B objBSecond = objBOne;Console.WriteLine("----------------------Assign to Second object-----------------------------------");Console.WriteLine("----------------------Assign Value to objcet 'ObjSecond' 3 & 3-----------------------------------");objBSecond.Height = "3";objBSecond.Weight = "3";Console.WriteLine("----------------------Call first obj-----------------------------------");Console.WriteLine("Property Height " + objBOne.Height + "Weight " + objBOne.Weight);Console.WriteLine("----------------------Call second obj-----------------------------------");Console.WriteLine("Property Height " + objBSecond.Height + "Weight " + objBSecond.Weight);}}

    Lalit Raghav
    April 16, 2015
    0

    http://dotnet-munesh.blogspot.in/2013/12/difference.html

    Munesh Sharma
    October 09, 2014
    0

    Stru 1.values types,so stored on stack 2.with or without using new keyword we can create the object of the stru's. 3.it consists only construters not destucter. 4.inside the no initilization takes place. 5.not possible to inhrit another struct but from interface possible

    Sunil Gaded
    August 28, 2014
    0

    class Structure 1.class has all access 1.structures cannot have protected and internal modifiers protected 2.Value type 2.reference type 3.supports inheritance 3.doesnot support inheritance

    varunkumar reddy
    August 23, 2014
    0

    http://www.codeproject.com/Articles/265755/Difference-between-Class-and-Structure-in-NET

    Ankur Jain
    August 18, 2014
    0

    1. Structure is Value Type. Class is Reference Type. 2. Structure is stored on Stack. Class is stored on Heap. 3. Structure does not support Inheritance. Class supports Inheritance. 4. 'this' pointer does not supported by Structure. 'this' pointer is only supported by Classes. 5. Structure do not require Constructor. Classes require Constructors. 6. Only Interface Inheritance is possible in Structure. 7. Default access specifier for Structure is public For Class, default access specifier is private.

    Abhishek Yadav
    July 27, 2014
    0