Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class Array
- : ICloneable, IList, ICollection, IEnumerable {
- public partial class Array<T>
- : ICloneable, IList<T>, ICollection<T>, IEnumerable<T> {
- public partial class Array: Array<object> {
- Mammoth[] mammoths = new Mammoth[10];
- Animal[] animals = mammoths; // Covariant conversion
- animals[1] = new Giraffe(); // Run-time exception
- Array<Mammoth> mammoths = new Array<Mammoth>(10);
- Array<Animal> animals = mammoths; // Not allowed.
- IEnumerable<Animals> animals = mammoths; // Covariant conversion
- ICollection<Mammoth> collection = new Mammoth[10]; // Cast to interface type
- collection.Add(new Mammoth()); // Run-time exception
- ICollection<Mammoth> mammoths = new Array<Mammoth>(10);
- ICollection<Animal> animals = mammoths; // Not allowed
- interface IList<out T> : ICollection<T>
- {
- T this[int index] { get; }
- int IndexOf(object value);
- }
- interface ICollection<out T> : IEnumerable<T>
- {
- int Count { get; }
- bool Contains(object value);
- }
- Array<Mammoth> mammoths = new Array<Mammoth>(10);
- IList<Animals> animals = mammoths; // Covariant conversion
- Array ary = Array.Copy(.....);
- int[] values = (int[])ary;
- for (Foo *foo = beginArray; foo != endArray; ++foo)
- {
- // use *foo -> which is the element in the array of Foo
- }
- int[,] foo2 = new int[2, 3];
- foreach (var type in foo2.GetType().GetInterfaces())
- {
- Console.WriteLine("{0}", type.ToString());
- }
- Array array = foo2;
- Console.WriteLine("Length = {0},{1}", array.GetLength(0), array.GetLength(1));
- array.GetType().GetMethod("GetLength").Invoke(array, 0); // don't...
- ((Array)someArray).GetLength(0); // do!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement