at struct cannot have instance field initializers in structs
Code:
struct time
{
private int x = 5; // compile-time error
}
Code:
struct time
{
private time() // compile-time error
{
}
}
Code:
struct time
{
private int x; // compile-time error
public time(int a)
{
}
}
struct use values so it's in stack but type use ref so it's in heap
can't declare a defualt constructor at struct but u can at class
at struct it will generate a default const. for u even if u got one but it won't at class
struct won't intialize a field for u at ur constructor but class will
at struct you are not allowed to initialize instance fields at there point of decleration(but u still need to assigned value to it before it return to the caller) but u can at class
Code:
struct time
{
private int x = 10; // compile-time error
}
one more info
at struct you can declare a field witout new keyword (as struct is values) but once u try to access it , it will just give an error , but with new keyword you declare them with defualt values aka 0 , false and null , here is an example
Code:
class Program
{
static void Main(string[] args)
{
time now ;
Console.WriteLine(now.hr); // compile-time error
}
}
struct time
{
public int hr, min, sec;
}
Code:
class Program
{
static void Main(string[] args)
{
time now = new time();
Console.WriteLine(now.hr); // no errors , result is 0
}
}
struct time
{
public int hr, min, sec;
}
if u found it helpful lemme know to give it a try at arrays and collections , im reading tons of pages and sum up for my self in lines as refrence and got no problem to share them with u






provides more insight than your post.
