Overflowded!
-
public class foo { int mBar; public int Bar { get { return Bar; } set { mBar = value; } } }
This one took me an hour to figure out, due to lack of confidence. I was so sure that I had done something terribly wrong, while the answer was just right in front of me. VS StackOverFlowed without a (stack)trace, but the pointer stopped at the 'public int Bar', But strangely this happened right at startup (not during build), looong before the property was ever used. So I thought something was horribly wrong, instead of just looking where the pointer stopped. I hope you see it quicker than me :p
-
public class foo { int mBar; public int Bar { get { return Bar; } set { mBar = value; } } }
This one took me an hour to figure out, due to lack of confidence. I was so sure that I had done something terribly wrong, while the answer was just right in front of me. VS StackOverFlowed without a (stack)trace, but the pointer stopped at the 'public int Bar', But strangely this happened right at startup (not during build), looong before the property was ever used. So I thought something was horribly wrong, instead of just looking where the pointer stopped. I hope you see it quicker than me :p
joon vh. wrote:
get { return Bar; }
Took me 3 seconds, actually less than that.
-Prakash
-
joon vh. wrote:
get { return Bar; }
Took me 3 seconds, actually less than that.
-Prakash
-
public class foo { int mBar; public int Bar { get { return Bar; } set { mBar = value; } } }
This one took me an hour to figure out, due to lack of confidence. I was so sure that I had done something terribly wrong, while the answer was just right in front of me. VS StackOverFlowed without a (stack)trace, but the pointer stopped at the 'public int Bar', But strangely this happened right at startup (not during build), looong before the property was ever used. So I thought something was horribly wrong, instead of just looking where the pointer stopped. I hope you see it quicker than me :p
-
-
public class foo { int mBar; public int Bar { get { return Bar; } set { mBar = value; } } }
This one took me an hour to figure out, due to lack of confidence. I was so sure that I had done something terribly wrong, while the answer was just right in front of me. VS StackOverFlowed without a (stack)trace, but the pointer stopped at the 'public int Bar', But strangely this happened right at startup (not during build), looong before the property was ever used. So I thought something was horribly wrong, instead of just looking where the pointer stopped. I hope you see it quicker than me :p
-
Must admit I've been bitten a couple of times with that one, although it only takes less than a second to discover and fix.
.net is a box of never ending treasures, every day I get find another gem.
not if it's a first time encounter, and you're me, and convinced, due to lack of confidence, that you must've severely broken something because you get an Error without a stacktrace.
Visual Studio can't evaluate this, can you?
public object moo { __get { return moo; } __set { moo = value; } }
-
of course, I loosened it up for you.
Visual Studio can't evaluate this, can you?
public object moo { __get { return moo; } __set { moo = value; } }
yeah, I figured that now :) Thanks.
-Prakash
-
public class foo { int mBar; public int Bar { get { return Bar; } set { mBar = value; } } }
This one took me an hour to figure out, due to lack of confidence. I was so sure that I had done something terribly wrong, while the answer was just right in front of me. VS StackOverFlowed without a (stack)trace, but the pointer stopped at the 'public int Bar', But strangely this happened right at startup (not during build), looong before the property was ever used. So I thought something was horribly wrong, instead of just looking where the pointer stopped. I hope you see it quicker than me :p
As I said on multiple occasions: properties are a bad idea - methods with a syntax of data members X|
-
As I said on multiple occasions: properties are a bad idea - methods with a syntax of data members X|
In Java you have something like:
private String name;
public String get_Name()
{
return name;
}
public void set_Name(String name)
{
this.name = name;
}Why is it so bad to use this instead:
public String Name
{
get { return name; }
set { name = value; }
}Which is internally used as get_Name and set_Name, you can check this by trying to add a method with signature public string get_Name() and it will complain. The biggest advantage you get is more readable code.
person.Name += " Something";
instead of
person.set_Name(person.get_Name() + " Something");
-
In Java you have something like:
private String name;
public String get_Name()
{
return name;
}
public void set_Name(String name)
{
this.name = name;
}Why is it so bad to use this instead:
public String Name
{
get { return name; }
set { name = value; }
}Which is internally used as get_Name and set_Name, you can check this by trying to add a method with signature public string get_Name() and it will complain. The biggest advantage you get is more readable code.
person.Name += " Something";
instead of
person.set_Name(person.get_Name() + " Something");
Steve Hansen wrote:
Why is it so bad to use this instead: public String Name{get { return name; }set { name = value; }}
I am not talking about implementing properties, but the way they are used. They look like data members, but are functions and that not only leads to bugs like the one described in this topic, but also reduces readability of the code.
Steve Hansen wrote:
The biggest advantage you get is more readable code. person.Name += " Something"; instead of person.set_Name(person.get_Name() + " Something");
Both are bad.
-
public class foo { int mBar; public int Bar { get { return Bar; } set { mBar = value; } } }
This one took me an hour to figure out, due to lack of confidence. I was so sure that I had done something terribly wrong, while the answer was just right in front of me. VS StackOverFlowed without a (stack)trace, but the pointer stopped at the 'public int Bar', But strangely this happened right at startup (not during build), looong before the property was ever used. So I thought something was horribly wrong, instead of just looking where the pointer stopped. I hope you see it quicker than me :p
Just replace "get { return Bar; }" to "get { return this.mBar; }. I suggest you remove m from "mBar" and replace it with a "_":rolleyes:
█▒▒▒▒▒██▒█▒██ █▒█████▒▒▒▒▒█ █▒██████▒█▒██ █▒█████▒▒▒▒▒█ █▒▒▒▒▒██▒█▒██