2010-07-10 17 views

Respuesta

139
void Foo() 
{ 
    throw new OutOfMemoryException(); 
} 

:)))

+4

+1 - tirarlo FTW –

+18

respuesta obvia es obvioius. – Will

+10

+1 técnicamente correcto - el * mejor tipo * correcto –

5

Crea una secuencia muy, muy grande. Probablemente:

string s = new string('a', int.MaxValue); 

será suficiente.

Si no, puede concat para construir una cadena aún más grande.

string ss = string.Concat(s, s); 
4

Esto lanzará una OutOfMemoryException:

string s = " "; 
while (true) s += s; 
4
for(var s=" ";;s+=s); 
3
var x = new long[Int32.MaxValue]; 

Eso debería hacerlo.

2

Puede utilizar este:

new int[(ulong)-1]; 
Cuestiones relacionadas