3

I'm not sure where I saw this, and I'm certainly not getting the syntax past the compiler. Is it possible to use the 'class' C# keyword as part of a method parameter signature?

foo(string x, class y) { }

Anyone else see something like this? thanks, -gene

1
  • 1
    It really depends on how you want to call it; that could be object, Type, or generics - possibly a few others too. Commented Aug 18, 2009 at 14:11

4 Answers 4

8

Should you be using object maybe? It looks like you are trying to specify a parameter that can have any type, in which case you should use object, since everything derives from it.

Sign up to request clarification or add additional context in comments.

Comments

2

I don't think you can use it as in your example, but if you would want to use the word "class" as a parameter name, that is doable by prefixing it with @:

foo(string @class) { }

Comments

2

It is possible to use the word class in in a generic method definition:

foo<T>(T object) where T:class

Comments

0

Use object if you want to be able to pass y as anything:

foo(string x, class y) { }

use generics if you want to state y has to be an object of a class - not a struct or an internace for example.

foo<MyType>(string x, MyType y) where MyType : class { }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.