2010-07-10 14 views

risposta

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

:)))

+4

+1 - gettandolo FTW –

+18

risposta ovvia è obvioius. – Will

+10

+1 tecnicamente corretto - il * tipo migliore * corretto –

5

Creare una stringa molto, molto grande. Probabilmente:

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

sarà sufficiente.

In caso contrario, è possibile concatenarlo per creare una stringa ancora più grande.

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

Ciò getta una OutOfMemoryException:

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

Che dovrebbe farlo.

2

È possibile utilizzare questo:

new int[(ulong)-1]; 
Problemi correlati