2010-07-10 104 views

回答

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

:)))

+4

+1 - 把它扔FTW – 2010-07-10 23:16:08

+18

明顯的答案是obvioius。 – Will 2010-07-10 23:16:42

+10

+1技術上正確 - 正確的*最好* – 2010-07-11 01:47:48

5

創建一個非常非常大的字符串。可能是:

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

就足夠了。

如果沒有,你可以連接它來建立更大的字符串。

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

這並拋出OutOfMemoryException

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

應該這樣做。

2

您可以使用此:

new int[(ulong)-1]; 
相關問題