Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
Interface static member ?
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.csharp.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

TruongLapVi
Hi,

Why C# does not support Interface static member ?

Some time I want implement NullObject Pattern:

public interface INullObject {
public static INullObject Null {
get { return NullObject.Instance; } // !!! Wrong, C# not support ?
}
}
public class NullObject {
private static instance; // Singleton pattern
private NullObject () {};
static NullObject() { instance = new NullObject; }
public static NullObject Null {
get { instance; )
}
}
}
public class NullObjectImpl : INullObject, FooClass {
...........
}

--
Vi

Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
Frank Oquendo
TruongLapVi wrote:
[Original message clipped]

A static membre belongs to a particular class. An interface is not a class.
Even so, interfaces are not allowed to have method definitions. That's an
implementation detail.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)

Reply to this message...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
TruongLapVi
> A static membre belongs to a particular class. An interface is not a
class.
[Original message clipped]

I think that static member is not instance member, ie we needn't creat new
instance for calling static member, so I expect that C# should support this
feature.

Thank for your answer.

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Vadym Stetsyak
"TruongLapVi" <Click here to reveal e-mail address> wrote in message
news:e3#Click here to reveal e-mail address...
[Original message clipped]

interface is a class declared as abstract class and all the methods defined
in it are also abstract.
Interfaces define mereley methods and classes that implement interfaces must
implement those methods.

[Original message clipped]

it supports this feature but not with interfaces.
Interfaces may only contain signatures for methods, properties, indexers and
events

Reply to this message...
Vote that this is a GOOD answer...
 
Email Archiving and Email Filing - what’s the difference?
Web-based task/todo list management
 
    
Dmitriy Lapshin [C# / .NET MVP] (VIP)
Interfaces cannot contain static members because members declared in an
interface are inheretly virtual since their polymorphic implementation is
assumed. And a static member cannot be virtual.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"TruongLapVi" <Click here to reveal e-mail address> wrote in message
news:e3%Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
dilipdotnet at apdiya.com
Hello Vi,
Interface only describes behaviour and serves the purpose of describing
a contractual obligation for classes implementing the interface that
certain behaviour is implemented.
The .net framework is not capable of downcasting objects to their
interfaces. If for example object A implements interface I1 and I2 the
framework will not be able to intelligently downcast the object to I1 or
I2. whereas if an abstract class is used there is no issue as there is
no multiple inheritence.
Hope that makes more sense than its confusing
Thanks

TruongLapVi wrote:

[Original message clipped]

--
Regards,
Dilip Krishnan
MCAD, MCSD.net
dilipdotnet at apdiya dot com
Reply to this message...
Vote that this is a GOOD answer...
 
 
 




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734