ArrayList的GetType方法获取当前实例的类型。
C# ArrayList中的GetType方法示例
public class MyArrayList { public static void Main() { //Creates a new ArrayList. ArrayList myArray = new ArrayList(); myArray.Add("one"); myArray.Add("two"); myArray.Add("three"); myArray.Add("four"); myArray.Add("five"); //create the another arraylist ArrayList myArray1 = new ArrayList(); myArray1.Add("six"); myArray1.Add("seven"); myArray1.Add("eight"); myArray1.Add("nine"); myArray1.Add("ten"); //create the new collection say stack Stack stack = new Stack(); stack.Push("xyz"); stack.Push("PQR"); //perform gettype method Console.WriteLine("myArray and myArray1 are the same type: {0}", Object.ReferenceEquals(myArray.GetType(), myArray1.GetType())); Console.WriteLine("myArray and stack are the same type: {0}", Object.ReferenceEquals(myArray.GetType(), stack.GetType())); } }
日期:2020-04-11 22:50:32 来源:oir作者:oir