2009-10-01 35 views

Respuesta

79

tiene varias opciones:

string[] items = { "Item1", "Item2", "Item3", "Item4" }; 

string[] items = new string[] 
{ 
    "Item1", "Item2", "Item3", "Item4" 
}; 

string[] items = new string[10]; 
items[0] = "Item1"; 
items[1] = "Item2"; // ... 
+5

no se olvide el 'string [] = {artículos "Elemento1", "Item2", "Elemento3", "elemento4" }; 'atajo. – LukeH

+0

@Luke: Gracias, de hecho lo olvidé. –

2
string[] str = new string[]{"1","2"}; 
string[] str = new string[4]; 
7

básicos:

string[] myString = new string[]{"string1", "string2"}; 

o

string[] myString = new string[4]; 
myString[0] = "string1"; // etc. 

avanzada: desde una lista

list<string> = new list<string>(); 
//... read this in from somewhere 
string[] myString = list.ToArray(); 

De StringCollection

StringCollection sc = new StringCollection(); 
/// read in from file or something 
string[] myString = sc.ToArray(); 
+0

¿Alguien puede agregar un ejemplo de "De una lista" anterior, pero para el caso de cargar el contenido de 2 listas en una matriz bidimensional (no dentada, es decir, doble [,])? – skinnedKnuckles

Cuestiones relacionadas