Using a struct without initialization

  • Thread starter Thread starter Heiko65456465
  • Start date Start date
H

Heiko65456465

Guest
Hello,

I have declared 2 variables in a UWP app, which are of a type of an own structure. But the compiler gives the error CS0165 if I want to assign a value to a property. A variable of type Windows.Foundation.Size, which is not initialized in my code, can be assigned to another variable without error message. I can also set or read one of its properties, also without error message.

Furthermore, no compiler error is generated if the property of my structure is a field instead. This also seems not logical.

What is the difference between Windows.Foundation.Size and MyStructX?

public struct MyStructA
{
public int A;
}

public struct MyStructX
{
public int X { get; set; }
}

public MainPage()
{
Size sz;
Size sz2 = sz; // OK
double w = sz.Width; // OK

sz.Width = 33; // OK


MyStructA mstA;
// MyStructA mstA2 = mstA; // CS0165
// int a = mstA.A; // CS0170

mstA.A = 33; // OK


MyStructX mstX;
// MyStructX mstX2 = mstX; // CS0165
// int x = mstX.X; // CS0165

mstX.X = 33; // CS0165
}


Best Regards,
Heiko

Continue reading...
 
Back
Top