Jon said:
Because the textual order of declaration is almost entirely irrelevant
in C#.
You can access methods "earlier" than they're declared etc. This isn't
C
The only impact of the order is when it comes to initialization -
variables are initialized in the order in which they're declared. It's
a bad idea to use that though - it's too easy to reorder variables and
break things.
Actually, I did notice the following behaviour in the VS2005 editor just
yesterday when trying to show something unrelated to a co-worker.
- Create empty class.
- Add private variables to the class definition, but at the bottom, like:
class Test
{
private int one;
private bool two;
}
- When adding properties *above* the private variables you will be be
exposing, you will not see them in Intellisense when writing get/set. i.e.:
class Test
{
public int One
{
get { return this. // << Right here, it shows me the "One"
// Property, but not the private "one"
}
private int one;
private bool two;
}
It threw me off a bit, because I'm lazy and love intellisense. Anyway, I
generally out of habit write my private members first, then
constructors, then properties and so on -- it just makes sense to my
brain -- but it does appear to a degree that it affects at least the
IDE, if not the compiler.
Also, just as a final note, I only see this behaviour in these specific
circumstances. It does not generate a compile error if you manually
finish the line with the lower case local variable "one".
Chris.