.


:




:

































 

 

 

 


Return string.Compare(x.name, y.name, StringComparison.Ordinal);




}

}

class Inventory { public string name; double cost; int onhand;

public Inventory(string n, double c, int h) { name = n; cost = c; onhand = h;

}

public override string ToString() { return

String.Format("{0,-10} : {1,6:} : {2}", name, cost, onhand);

}

}

class GenericIComparerDemo { static void Main() {

CompInv<Inventory> comp = new CompInv<Inventory>();

List<Inventory> inv = new List<Inventory>();

// . inv.Add(new Inventory("", 5.95, 3));

inv.Add(new Inventory("", 8.29, 2)); inv.Add(new Inventory("", 3.50, 4)); inv.Add(new Inventory("", 19.88, 8));

Console.WriteLine(" :"); foreach(Inventory i in inv) {

Console.WriteLine (" " + i);

}

Console.WriteLine ();

// , IComparer. inv.Sort(comp);

Console.WriteLine(" :"); foreach(Inventory i in inv) {

Console.WriteLine (" " + i);

}

}

}

StringComparer

. , . , , , , , . . ( ) IComparer. StringComparer.

StringComparer 21 . IComparer, IComparer<String>, IEqualityComparer, IEqualityComparer<String>. , StringComparer IComparer . StringComparer , StringComparer, . 21, : CurrentCulture, CurrentCulturelgnoreCase, InvariantCulture, InvariantCulturelgnoreCase, Ordinal, OrdinallgnoreCase. .

, SortedList<TKey, TValue> , .

SortedList<string, int> users =

new SortedList<string, int>(StringComparer.Ordinal);

, , . , , foreach, , . , IEnumerator IEnumerator<T>.

IEnumerator , Current, .

object Current { get; }

IEnumerator<T> Current.

Current { get; }

Current . Current , , .





:


: 2016-12-03; !; : 416 |


:

:

, .
==> ...

1748 - | 1573 -


© 2015-2024 lektsii.org - -

: 0.016 .