Will I create any problems if I make all my class properties structure members like the following code does?
private struct Properties
{
public int p1;
public int p2;
}
private Properties P;
public int p1 { get { return P.p1; } set { P.p1 = value; } }
public int p2 { get { return P.p2; } set { P.p2 = value; } }
I did the analogous thing in VB for years, but then speed was not important. Now I am just getting started with C# on real time projects where speed matters. Thanks for any feedback!
Yes. The problem will be unnecessary code. You could just shorten your code like this, and it will still function the same:
public int p1 { get;set; }
public int p2 { get;set; }
If you wanted to set breakpoints on getter or setter, you could use a backing private field like so:
private int _p1;
public int P1
{
get { return _p1; }
set { _p1 = value; }
}
private int _p2;
public int P2
{
get { return _p2; }
set { _p2 = value; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With