tags:

views:

74

answers:

2

Anyone care to guess what currentIndex 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.

+1  A: 

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.

ydobonmai
Right the variable name makes no sense in this context, it's a copy and paste. This is returning 110 though, which is confusing me to say the least.
jdelator
Do you maybe have another extension method called `Min` ?
leppie
No. I'm not sure what is going on.
jdelator
+2  A: 

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:\>
leppie
I get same result. I'm not sure why I'm getting this in my function...
jdelator
Look for another function called `Min` :) I suspect you have another extension method getting preferred to the Linq one.
leppie
I looked and even tried to step into the function, no dice :(
jdelator
I think it had to something with a local variable in a function having the same name as a member variable of the class. I'll just work around the issue.
jdelator