By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,293 Members | 1,397 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,293 IT Pros & Developers. It's quick & easy.

What replace "this" in static class?

P: n/a
Hi,

I have a class that I modified to be static. It is now a public sealed
class and all function are static, no more constructor but a init()
function to do the constructor job.

This class inherit from a QuickFix.Application class. I have this object:
private static SocketInitiator qfxInitiator;

When instantiated, its constructor need a "QuickFix.Application" object.
And previously I was using "this" keyword because the class inherit
from "QuickFix.Application", but now that the class is static, is there
a keyword to point at this static class?

Thank you :)
Marty
Dec 7 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
You can have static constructors.
class MyClass
{
// Static constructor:
static MyClass()
{
Console.WriteLine("The static constructor invoked.");
}
public static void MyMethod()
{
Console.WriteLine("MyMethod invoked.");
}
}

is the example in the help - calling MyMethod for the first time will
cause the constructor to be called.

I don't believe you can use "this" in a static class - I can't really
think of a reason to do so, either. Why do you want to do so?

Andy D

Dec 7 '05 #2

P: n/a
And previously I was using "this" keyword because the class inherit
from "QuickFix.Application", but now that the class is static, is there
a keyword to point at this static class?


No. It needs an _instance of_ the class and by making your class
static you've made it impossible to create instances of it. Therefore
there's no way to do what you want.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dec 7 '05 #3

P: n/a
Hi,

There is no way of doing what you want, all you can do is get access to
the protected static fields of the parent class.

there is no way of doing what you were doing before.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Marty" <xm******@hotmail.com> wrote in message
news:urElf.138488$y_1.49549@edtnps89...
Hi,

I have a class that I modified to be static. It is now a public sealed
class and all function are static, no more constructor but a init()
function to do the constructor job.

This class inherit from a QuickFix.Application class. I have this object:
private static SocketInitiator qfxInitiator;

When instantiated, its constructor need a "QuickFix.Application" object.
And previously I was using "this" keyword because the class inherit from
"QuickFix.Application", but now that the class is static, is there a
keyword to point at this static class?

Thank you :)
Marty

Dec 7 '05 #4

P: n/a
Originally, your class, as a derived class of QuickFix.Application,
held within it an instance of QuickFix.Application. Now that it's is a
static class, this relationship is broken.

It fix this, you must make explicit what was previous implict. Your
class can no longer derive from QuickFix.Application (as this relationship
is meaningless when one is a static class and the other is an instance
class), but should contain a explicit QuickFix.Application member.

--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
"Marty" <xm******@hotmail.com> wrote in message
news:urElf.138488$y_1.49549@edtnps89...
Hi,

I have a class that I modified to be static. It is now a public sealed
class and all function are static, no more constructor but a init()
function to do the constructor job.

This class inherit from a QuickFix.Application class. I have this object:
private static SocketInitiator qfxInitiator;

When instantiated, its constructor need a "QuickFix.Application" object.
And previously I was using "this" keyword because the class inherit
from "QuickFix.Application", but now that the class is static, is there
a keyword to point at this static class?

Thank you :)
Marty

Dec 7 '05 #5

P: n/a
Thank you everybody for your fast reply. Thinking that I might have no
"escape" I already restore my class to its previous state, being not
static. I think it will stay like that.

Have a nice day :)
Marty

Marty wrote:
Hi,

I have a class that I modified to be static. It is now a public sealed
class and all function are static, no more constructor but a init()
function to do the constructor job.

This class inherit from a QuickFix.Application class. I have this object:
private static SocketInitiator qfxInitiator;

When instantiated, its constructor need a "QuickFix.Application" object.
And previously I was using "this" keyword because the class inherit
from "QuickFix.Application", but now that the class is static, is there
a keyword to point at this static class?

Thank you :)
Marty

Dec 7 '05 #6

P: n/a
Very interesting, thank you James.
Marty

James Curran wrote:
Originally, your class, as a derived class of QuickFix.Application,
held within it an instance of QuickFix.Application. Now that it's is a
static class, this relationship is broken.

It fix this, you must make explicit what was previous implict. Your
class can no longer derive from QuickFix.Application (as this relationship
is meaningless when one is a static class and the other is an instance
class), but should contain a explicit QuickFix.Application member.

Dec 7 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.