我有一个场景,其中有一个字典在给定时间可能有也可能没有键值.我目前正在测试是否以下列方式存在该值,但是想知道这是否是最好的方法,或者是否有更好的方法来处理它.
int myInt;
try
{
myInt = {Value From Dictionary};
}
catch
{
myInt = 0;
}
Run Code Online (Sandbox Code Playgroud)
有什么输入?谢谢.
我有一个名为数字的数组,我想用for循环填充:
int[] numbers;
for ( int i = 0; i <=10; i++)
{
// want to populate the array with a sequence of 0-10
}
Run Code Online (Sandbox Code Playgroud)
如何将上面生成的11个值for循环填充到我的数组中?