Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array casting

Status
Not open for further replies.

nille

IS-IT--Management
Mar 14, 2002
5
DK
Hi,
I am new to C#, but have been programming in Java for a while. What I want know is a way of creating an Array of a specific type, without knowing which type it is...
In Java you would to this:

public Object[] createArray(Class type, int size) {
return Array.newInstance(type, size);
}

This function can then be used like this:

Component[] componentArray = (Component[])createArray(Component.class, 8);

How can this be done in C#?

Thanks on advance,
Nille.
 
Sorry, solved it...

String[] s = Array.CreateInstance(typeof(String),mySize));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top