C# Strange Behavior

Posted by Betamoo on Stack Overflow See other posts from Stack Overflow or by Betamoo
Published on 2010-05-08T09:02:34Z Indexed on 2010/05/08 9:08 UTC
Read the original article Hit count: 137

Filed under:
|
|
|
|

I have a custom struct :

struct A
{
    public int y;
}

a custom class with empty constuctor:

class B
{
    public A a;
    public B()
    {
    }
}

and here is the main:

static void Main(string[] args)
{
    B b = new B();
    b.a.y = 5;//No runtime errors!
    Console.WriteLine(b.a.y);
}


When I run the above program, it does not give me any errors, although I did not initialize struct A in class B constructor..'a=new A();'

© Stack Overflow or respective owner

Related posts about c#

Related posts about struct