Re: Rationale for CS0536?
- From: "Daniel O'Connell [C# MVP]" <onyxkirx@xxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 12 Sep 2005 11:59:34 -0500
> Still, this seems to be a cumbersome way to accomplish that behaviour.
> So, to come back to the basic question - why did they make it the way
> it is? Any case where there would be ambiguities when calling static
> members via instances?
>
It is this way because it distinguishes between an action on the type and on
the instance itself. Jon Skeet, another MVP who wanders these groups, likes
to use Thread.Sleep as an example
Thread t = ...;
t.Sleep(10);
What does that look like its doing to you? To me it looks like its putting
the thread referenced by t to sleep, however, its not. It is putting the
current thread to sleep since Sleep is a static method. If you did around
you will find alot of examples where that occurs.
Another example might be:
string s = "cat";
s = s.Concat("apple", "orange");
Console.WriteLine(s);
The expected result of that operation looks like it should be
"catappleorange", but it is actually "appleorange" since Concat is static
and does not act on the original variable. By not allowing statics to be
called through instances you don't have issues like that.
.
- Follow-Ups:
- Re: Rationale for CS0536?
- From: elvis_the_king@xxxxxx
- Re: Rationale for CS0536?
- References:
- Rationale for CS0536?
- From: elvis_the_king
- Re: Rationale for CS0536?
- From: Nicholas Paldino [.NET/C# MVP]
- Re: Rationale for CS0536?
- From: elvis_the_king@xxxxxx
- Rationale for CS0536?
- Prev by Date: Re: What is a "Reference"
- Next by Date: Re: What is a "Reference"
- Previous by thread: Re: Rationale for CS0536?
- Next by thread: Re: Rationale for CS0536?
- Index(es):
Relevant Pages
|