Hi,
What is the difference between declaring a class as static and delaring
methods as static (class not static)?
Also, when do we use a static constructor? 9 1452
HL <HL@discussions.microsoft.com> wrote: What is the difference between declaring a class as static and delaring methods as static (class not static)?
Declaring the class static forces everything in it to be static and
makes sure there are *no* constructors - not even a private one, or a
parameterless one supplied by the compiler.
Also, when do we use a static constructor?
When you need to perform some initialisation for the type itself -
typically setting up things like maps which are used elsewhere.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Declaring the class static forces everything in it to be static and makes sure there are *no* constructors - not even a private one, or a parameterless one supplied by the compiler.
Does that work in C#? Help says static doesn't apply to types.
Michael
"Michael C" <no****@nospam.com> wrote in message
news:es**************@TK2MSFTNGP12.phx.gbl... "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om... Declaring the class static forces everything in it to be static and makes sure there are *no* constructors - not even a private one, or a parameterless one supplied by the compiler.
Does that work in C#? Help says static doesn't apply to types.
Michael
Its a feature new to version 2.0 of C#
Regards
Richard Blewett - DevelopMentor http://www.dotnetconsult.co.uk/weblog http://www.dotnetconsult.co.uk
Hi,
Your explanation on Static class was helpful. But I didn't get the
static constructor part. Let's say I have a class that has a static
constructor, and I attempt to create 2 instances of that type , will there
be 1 instance or 2 instances? I think I am confusing between Singleton and
static here. Can you please give a detailed explanation.
"Jon Skeet [C# MVP]" wrote: HL <HL@discussions.microsoft.com> wrote: What is the difference between declaring a class as static and delaring methods as static (class not static)?
Declaring the class static forces everything in it to be static and makes sure there are *no* constructors - not even a private one, or a parameterless one supplied by the compiler.
Also, when do we use a static constructor?
When you need to perform some initialisation for the type itself - typically setting up things like maps which are used elsewhere.
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too
Yes it works in C#.
You can declare a class static, and you can also declare a static
constructor.
I think the static class feature was only added in framework v2.
Sharon.
"Michael C" <no****@nospam.com> wrote in message
news:es**************@TK2MSFTNGP12.phx.gbl... "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om... Declaring the class static forces everything in it to be static and makes sure there are *no* constructors - not even a private one, or a parameterless one supplied by the compiler.
Does that work in C#? Help says static doesn't apply to types.
Michael
Hi.
1. You can not instanciate a static class.
2. The static constructor is invoked, when the class is loaded.
Saron.
"HL" <HL@discussions.microsoft.com> wrote in message
news:34**********************************@microsof t.com... Hi,
Your explanation on Static class was helpful. But I didn't get the static constructor part. Let's say I have a class that has a static constructor, and I attempt to create 2 instances of that type , will there be 1 instance or 2 instances? I think I am confusing between Singleton and static here. Can you please give a detailed explanation.
"Jon Skeet [C# MVP]" wrote:
HL <HL@discussions.microsoft.com> wrote: > What is the difference between declaring a class as static and > delaring > methods as static (class not static)?
Declaring the class static forces everything in it to be static and makes sure there are *no* constructors - not even a private one, or a parameterless one supplied by the compiler.
> Also, when do we use a static constructor?
When you need to perform some initialisation for the type itself - typically setting up things like maps which are used elsewhere.
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too
"Richard Blewett [DevelopMentor]" <richard at nospam dotnetconsult dot co
dot uk> wrote in message news:% Its a feature new to version 2.0 of C#
That would explain why it's not working here :-)
Michael
Some useful information on Static constructors - here: http://www.ondotnet.com/pub/a/dotnet...or.html?page=1
"Sharon" wrote: Hi. 1. You can not instanciate a static class. 2. The static constructor is invoked, when the class is loaded. Saron.
"HL" <HL@discussions.microsoft.com> wrote in message news:34**********************************@microsof t.com... Hi,
Your explanation on Static class was helpful. But I didn't get the static constructor part. Let's say I have a class that has a static constructor, and I attempt to create 2 instances of that type , will there be 1 instance or 2 instances? I think I am confusing between Singleton and static here. Can you please give a detailed explanation.
"Jon Skeet [C# MVP]" wrote:
HL <HL@discussions.microsoft.com> wrote: > What is the difference between declaring a class as static and > delaring > methods as static (class not static)?
Declaring the class static forces everything in it to be static and makes sure there are *no* constructors - not even a private one, or a parameterless one supplied by the compiler.
> Also, when do we use a static constructor?
When you need to perform some initialisation for the type itself - typically setting up things like maps which are used elsewhere.
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too
Michael C <no****@nospam.com> wrote: "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om... Declaring the class static forces everything in it to be static and makes sure there are *no* constructors - not even a private one, or a parameterless one supplied by the compiler.
Does that work in C#? Help says static doesn't apply to types.
It's a new feature of C# 2.0.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Neil Zanella |
last post by:
Hello,
I would like to know whether it is possible to define static class methods
and data members in Python (similar to the way it can be done in C++ or Java).
These do not seem to be mentioned...
|
by: Steven D'Aprano |
last post by:
I've been doing a lot of reading about static methods in Python, and I'm
not exactly sure what they are useful for or why they were introduced.
Here is a typical description of them, this one...
|
by: Steven Livingstone |
last post by:
Anyone able to explain to me why you cannot define an interface that can
then be implemented using static methods?
I understand the C# CLS states this, but just interested in the reasons
behind...
|
by: Mauzi |
last post by:
hi,
this may sound odd and noob like, but what is the 'big' difference
between static and non-static funcitons ?
is there any performace differnce?
what is the best way to use them ?
thnx
...
|
by: Jay |
last post by:
Why are there static methods in C#. In C++ static was applied to data only
(I believe) and it meant that the static piece of data was not a part of the
object but only a part of the class (one...
|
by: Kevin Prichard |
last post by:
Hi all,
I've recently been following the object-oriented techiques discussed
here and have been testing them for use in a web application. There is
problem that I'd like to discuss with you...
|
by: MSDNAndi |
last post by:
Hi,
I have a baseclass (non-static) with some static and some non-static
methods/fields/properties.
In the baseclass in one of the static methods I need to do something like
"
somelogic...
|
by: Vivek Ragunathan |
last post by:
Hi
Are the members in a static class in C# class synchronized for multiple
thread access. If yes, are all static members in a C# class auto
synchronized ?
Regards
Vivek Ragunathan
|
by: DBC User |
last post by:
I have a class with bunch of static methods. I could regourp all the
static methods into seperate 3 or 4 classes. I was thinking about using
Singlton pattern for all these 4 classes so that it...
|
by: Steve Richter |
last post by:
in a generic class, can I code the class so that I can call a static
method of the generic class T?
In the ConvertFrom method of the generic TypeConvert class I want to
write, I have a call to...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
| |