Anyone care to guess what cu开发者_StackOverflow中文版rrentIndex is at the end of execution?
int[] ints = new int[] { -1, 12, 26, 41, 52, -1, -1 };
int minInt = ints.Min();
It's 110. Does anyone know why?
Wrapped it a main function below
using System;
using System.Linq;
class Sample {
public static void Main()
{
int[] ints = new int[] { -1, 12, 26, 41, 52, -1, -1 };
int minInt = ints.Min();
Console.WriteLine(minInt);
}
}
EDIT: I changed the variable name to minInt from currentIndex. It was a copy and paste from an function I'm debugging, which made sense in that context but not so much here.
Too long for a comment, but here is what I get.
C:\>copy con t.cs
using System;
using System.Linq;
class Sample {
public static void Main()
{
int[] ints = new int[] { -1, 12, 26, 41, 52, -1, -1 };
int minInt = ints.Min();
Console.WriteLine(minInt);
}
}
^Z
1 file(s) copied.
C:\>csc t.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.4926
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.
C:\>t
-1
C:\>
It should be -1. Also, I think the "currentIndex" variable naming is misleading. It is actually the minimum value in the array and not the current index. For example, if you add -2 in that array, the variable currentIndex in the above example would be -2.
精彩评论