What replace "this" in static class?

M

Marty

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
 
A

Andrew Ducker

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
 
M

Mattias Sjögren

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
 
I

Ignacio Machin \( .NET/ C# MVP \)

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,
 
J

James Curran

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
 
M

Marty

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top