tags:

views:

104

answers:

4

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

+8  A: 

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.

maxpower47
+2  A: 

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) { }
Fredrik Mörk
+2  A: 

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

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

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 { }
MattH