• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 501
  • Last Modified:

c# how do I pass a class in as a parameter to a function

I have a function that uses the lines below.  I would like to pass in the class to the function instead of how it is hardcoded now.  Is this possible?

string evClass = typeof(my.classname).FullName;
string evAssembly = typeof(my.classname).Assembly.FullName;

where my.classname is actually a class  
0
jackjohnson44
Asked:
jackjohnson44
  • 3
1 Solution
 
AlfredRobotCommented:
0
 
jackjohnson44Author Commented:
Thanks, but I don't understand that at all.  Can you please explain?
0
 
jackjohnson44Author Commented:
I am not trying to load an assembly either.  I plan to set everything to a variable, and don't mind presetting it and not using it.

I want
var x = class1
var y = class2

If I want to use x or y, I just use them.  I don't need to load anything at runtime.  I just don't want to have to have two different versions of the same function.
0
 
Carl TawnSystems and Integration DeveloperCommented:
You can either pass a Type to your method directly, use an overload (depending on how many types you want to use), or use a Generic method:
        private void DoSomething<T>()
        {
            string className = typeof(T).FullName;
            string classAsm = typeof(T).Assembly.FullName;
        }

// call method
DoSomething<Car>();
DoSomething<Person>();

Open in new window

0
 
jackjohnson44Author Commented:
Thanks!
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now