473,387 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Passing a "class" reference instead of an "object"

I want to be able to register a class that a factory can build for me at a
later time.

How can I pass the class's type to a method?

public class MyClass{
static public void Register(Type type)
{
// do something with: type
}
}

....
MyClass.Register(System.Windows.Forms.Form);
....

I would get the error: "X" is a 'type' but is used like a 'variable'.

--
Thanks,
Nov 16 '05 #1
2 1663
typeof

"Leicester B. Ford Jr." <Le*******@online.nospam> wrote in message
news:7E**********************************@microsof t.com...
I want to be able to register a class that a factory can build for me at a
later time.

How can I pass the class's type to a method?

public class MyClass{
static public void Register(Type type)
{
// do something with: type
}
}

...
MyClass.Register(System.Windows.Forms.Form);
...

I would get the error: "X" is a 'type' but is used like a 'variable'.

--
Thanks,

Nov 16 '05 #2
Hi LeiFord,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to pass a type object to a
static method. If there is any misunderstanding, please feel free to let me
know.

In C#, you need to use typeof() keywork to get the type of that class. For
example:

MyClass.Register(typeof(System.Windows.Forms.Form) );

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Dominik Kaspar | last post by:
i'm used to java and its strict way of defining variables. so how is it possible to reach something like a class variable in python? with the following code i didn't have much succes... class...
24
by: Hung Jung Lu | last post by:
Hi, Does anybody know where this term comes from? "First-class object" means "something passable as an argument in a function call", but I fail to see the connection with "object class" or...
7
by: Pablo J Royo | last post by:
Hello: i have a function that reads a file as an argument and returns a reference to an object that contains some information obtained from the file: FData &ReadFile(string FilePath); But ,...
0
by: Bill | last post by:
I keep hearing the term "first-class object and properties" used but have never been able to find a definition for this term. Can someone explain what this means?
3
by: muesliflakes | last post by:
I come from Java and an Object would be the class whist object would likly be the varible to an object. I get the impression with C# that object is just an alias to the Base Class Object. Can...
4
by: Piotr Perak | last post by:
Can someone explain the "object instance" term that is used i many of C# books? I have C++ background. In C++ instance and object meant the same. I could say that I have object of some class or...
5
by: hellrazor | last post by:
Hi there, I'm very new to dot net programming and webservices programming. I've managed to create simple webservices so far. Here's my problem: -I've been given a project which needs to...
14
by: =?GB2312?B?zPC5zw==?= | last post by:
Howdy, I wonder why below does not work. a = object() a.b = 1 # dynamic bind attribute failed... To make it correct, we have to create a new class: class MyClass(object): pass a =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.