Exemplo n.º 1
0
 // Retrieve a value from the array based on a key.
 public bool TryGetValue(TKey key, out TValue value)
 {
     foreach (TPair pair in array)
     {
         if (UtilGeneric.IsEqualTo(pair.key, key))
         {
             value = pair.value;
             return(true);
         }
     }
     value = default(TValue);
     return(false);
 }
Exemplo n.º 2
0
 // Gets the first key that has the given value.
 // Returns false if the given value doesn't exist in the dictionary.
 public static bool TryGetKey <TKey, TValue>(this Dictionary <TKey, TValue> dict,
                                             TValue value, out TKey key)
 {
     key = dict.FirstOrDefault(x => UtilGeneric.IsEqualTo(x.Value, value)).Key;
     return(dict.ContainsValue(value));
 }
Exemplo n.º 3
0
 void TestEqual <T>(T lhs, T rhs)
 {
     Test(UtilGeneric.IsEqualTo(lhs, rhs), "LHS = " + lhs + "; RHS = " + rhs);
 }
Exemplo n.º 4
0
    // Returns true if a tie exists in the number 1 spot.
    // TODO: This function is broken?? Fix it!
    public static bool IsLargestElementTied <T>(IEnumerable <T> collection)
    {
        List <T> ordered = collection.OrderByDescending(x => x).ToList();

        return(UtilGeneric.IsEqualTo(ordered[0], ordered[1]));
    }
Exemplo n.º 5
0
 // Returns true if the given result is the default result.
 private bool IsDefaultResult(T result)
 {
     return(UtilGeneric.IsEqualTo(result, resultDefault));
 }