Checking mobile SIMs Can someone improve this code? I need to eliminate the for loop.

public bool CheckMobileSim(List&lt;Mobile_Range&gt; numberRange, string MobileNumber)
{
    bool SimType = new bool();
    string NineDigits = MobileNumber.Substring(0, 9).ToString();
    long Number = Convert.ToInt64(NineDigits);
    if (numberRange != null)
    {
        if (numberRange.Count &gt; 0)
        {
            for (int i = 0; i &lt; numberRange.Count; i++)
            {
                if ((Number &gt;= numberRange[i].RangeStart &amp;&amp; Number &lt; numberRange[i].RangeEnd))
                {
                    SimType = true;
                    break;
                }

            }
        }
    }

    return SimType;
}
Refactoring step 1, remove unnecessary variables and braces and return early

public bool CheckMobileSim(List&lt;Mobile_Range&gt; numberRange, string MobileNumber)
{
    if(numberRange == null)
        return;
    string NineDigits = MobileNumber.Substring(0, 9).ToString();
    long Number = Convert.ToInt64(NineDigits);
    for (int i = 0; i &lt; numberRange.Count; i++)
        if ((Number &gt;= numberRange[i].RangeStart &amp;&amp; Number &lt; numberRange[i].RangeEnd))
            return true;

    return false;
}


I realize that breaks with the "single point of return" wisdom but I'm not a big fan. When you have small functions like this one, it doesn't make all that much sense.

Refactoring step 2, with that cleaned up it's easy to see how this fits into a simple LINQ query

public bool CheckMobileSim(IEnumerable&lt;Mobile_Range&gt; numberRange, string mobileNumber)
{
    if(numberRange == null || String.IsNullOrWhitespace(mobleNumber))
        return false;

    var nineDigits = mobileNumber.Substring(0, 9);
    var number = Convert.ToInt64(nineDigits);

    return numberRange.Any(n =&gt; number &gt;= n.RangeStart &amp;&amp; number &lt; n.RangeEnd);
}


Since this is a public method I added some checks and downcast List to IEnumerable, which is a looser contract and all you really need here.

By the way, .Net naming conventions are pascalCase for private and local variables CamelCase for public and protected. It's rare to use underscores.