PC Review


Reply
Thread Tools Rate Thread

Can we define a static class

 
 
ad
Guest
Posts: n/a
 
      18th Mar 2005
We can define a static member in a class.
But can we define a static class, so that all members are static?


 
Reply With Quote
 
 
 
 
Ajay Kalra
Guest
Posts: n/a
 
      18th Mar 2005
What do you mean by a static class? Are you thinking Singleton pattern so
that there is only one instance of this class?

--
Ajay Kalra [MVP - VC++]
(E-Mail Removed)


"ad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> We can define a static member in a class.
> But can we define a static class, so that all members are static?
>
>



 
Reply With Quote
 
VJ
Guest
Posts: n/a
 
      18th Mar 2005
nope..not as far as I know...

VJ

"ad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> We can define a static member in a class.
> But can we define a static class, so that all members are static?
>
>



 
Reply With Quote
 
Olorin
Guest
Posts: n/a
 
      18th Mar 2005
AFAIK, nay,
but you might be interested in this:

public abstract class MyClass
{
private MyClass() { }
public static void DoSomething() { ...}
}

HTH,
F.O.R.

PS: the private constuctor *is* important

 
Reply With Quote
 
ad
Guest
Posts: n/a
 
      18th Mar 2005
Thank,
I do'nt know what is Singleton pattern.

I want a static class so that every members in it can be static as the
module in vb.net

"Ajay Kalra" <(E-Mail Removed)> 级糶秎ン穝籇
:(E-Mail Removed)...
> What do you mean by a static class? Are you thinking Singleton pattern so
> that there is only one instance of this class?
>
> --
> Ajay Kalra [MVP - VC++]
> (E-Mail Removed)
>
>
> "ad" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > We can define a static member in a class.
> > But can we define a static class, so that all members are static?
> >
> >

>
>



 
Reply With Quote
 
Ajay Kalra
Guest
Posts: n/a
 
      18th Mar 2005
I dont know VB.Net. I think a sealed class with a private constructor will
be close to what you want.

--
Ajay Kalra [MVP - VC++]
(E-Mail Removed)


"ad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thank,
> I do'nt know what is Singleton pattern.
>
> I want a static class so that every members in it can be static as the
> module in vb.net
>
> "Ajay Kalra" <(E-Mail Removed)> 级糶秎ン穝籇
> :(E-Mail Removed)...
> > What do you mean by a static class? Are you thinking Singleton pattern

so
> > that there is only one instance of this class?
> >
> > --
> > Ajay Kalra [MVP - VC++]
> > (E-Mail Removed)
> >
> >
> > "ad" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > We can define a static member in a class.
> > > But can we define a static class, so that all members are static?
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
ad
Guest
Posts: n/a
 
      18th Mar 2005
Thank!
Can you give me an example?


"Ajay Kalra" <(E-Mail Removed)> 级糶秎ン穝籇
:#(E-Mail Removed)...
> I dont know VB.Net. I think a sealed class with a private constructor will
> be close to what you want.
>
> --
> Ajay Kalra [MVP - VC++]
> (E-Mail Removed)
>
>
> "ad" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Thank,
> > I do'nt know what is Singleton pattern.
> >
> > I want a static class so that every members in it can be static as the
> > module in vb.net
> >
> > "Ajay Kalra" <(E-Mail Removed)> 级糶秎ン穝籇
> > :(E-Mail Removed)...
> > > What do you mean by a static class? Are you thinking Singleton pattern

> so
> > > that there is only one instance of this class?
> > >
> > > --
> > > Ajay Kalra [MVP - VC++]
> > > (E-Mail Removed)
> > >
> > >
> > > "ad" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > We can define a static member in a class.
> > > > But can we define a static class, so that all members are static?
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Ajay Kalra
Guest
Posts: n/a
 
      18th Mar 2005
public sealed class CMyClass
{
private CMyClass() {}
public static void SomeMethod();
.....

}

Now you can use the static method as CMyClass.SomeMethod(). It will be good
if you can familiarize yourself with Singleton pattern. You will get away
from using static methods (which IMO is not really OO in any sense).

--
Ajay Kalra [MVP - VC++]
(E-Mail Removed)


"ad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thank!
> Can you give me an example?
>
>
> "Ajay Kalra" <(E-Mail Removed)> 级糶秎ン穝籇
> :#(E-Mail Removed)...
> > I dont know VB.Net. I think a sealed class with a private constructor

will
> > be close to what you want.
> >
> > --
> > Ajay Kalra [MVP - VC++]
> > (E-Mail Removed)
> >
> >
> > "ad" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Thank,
> > > I do'nt know what is Singleton pattern.
> > >
> > > I want a static class so that every members in it can be static as

the
> > > module in vb.net
> > >
> > > "Ajay Kalra" <(E-Mail Removed)> 级糶秎ン穝籇
> > > :(E-Mail Removed)...
> > > > What do you mean by a static class? Are you thinking Singleton

pattern
> > so
> > > > that there is only one instance of this class?
> > > >
> > > > --
> > > > Ajay Kalra [MVP - VC++]
> > > > (E-Mail Removed)
> > > >
> > > >
> > > > "ad" <(E-Mail Removed)> wrote in message
> > > > news:(E-Mail Removed)...
> > > > > We can define a static member in a class.
> > > > > But can we define a static class, so that all members are static?
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Bruce Wood
Guest
Posts: n/a
 
      18th Mar 2005
Using "abstract" in this situation won't work. The compiler will
complain that the class contains no abstract methods or properties.

You should, as Ajay pointed out, use "sealed" here, which indicates
that no other classes can inherit from this one.

 
Reply With Quote
 
=?ISO-8859-2?Q?Marcin_Grz=EAbski?=
Guest
Posts: n/a
 
      18th Mar 2005
Hi,

The static classes will came with C# 2.0.
I don't remember that their members will
be "static" by default. Only what i remember
these classes will allow only static members.

cheers!
Marcin

> We can define a static member in a class.
> But can we define a static class, so that all members are static?
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Invoking a Static Method in a Static Class =?Utf-8?B?SmltSGVhdmV5?= Microsoft C# .NET 3 7th Feb 2007 03:17 PM
Confusion over Static class and Static method! Anup Daware Microsoft C# .NET 2 5th Feb 2007 12:41 PM
Confusion over Static class and Static method! Anup Daware Microsoft ASP .NET 2 2nd Feb 2007 12:12 PM
Is This Safe? Static Class Reference In Static Function Amy L. Microsoft C# .NET 3 23rd Feb 2005 05:10 PM
Static class method return non-static object? Paschalis Pagonidis Microsoft C# .NET 8 10th Nov 2004 10:10 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:36 PM.