Structs may be a value type, but you CAN still use constructors (default and parameter ctors).
You can use the following code within your struct:
mystruct(){
tuble1 = val1;
tuble2 = val1;
}
mystruct( type1 val1, type2 val2){
tuble1 = val1;
tuble2 = val2;
}
You can call your constructor through initialization:
mystruct struc25 = new mystruct();
mystruct struc25 = new mystruct( val1, val2 );
By using the ââ¬Ånewââ¬Â keyword we are not actually instantiating the struct, instead we are calling the struct constructor.
Even though structs are value types (value semantics) C# has giving them functionality similar to a class.
|