Answer Posted / sharmin jose
Everything told above is correct except that ArrayList can
only contain "similar data type".
Please compile and execute the following code:
using System;
using System.Collections;
public class SamplesArrayList {
public static void Main() {
// Creates and initializes a new ArrayList.
ArrayList MyList = new ArrayList();
MyList.Add("Hello");
MyList.Add("World");
MyList.Add(1);
// Displays the properties and values of the
ArrayList.
Console.WriteLine( "MyList" );
Console.WriteLine( "\tCount: {0}", MyList.Count );
Console.WriteLine( "\tCapacity: {0}",
MyList.Capacity );
Console.Write( "\tValues:" );
PrintValues( MyList );
}
public static void PrintValues( IEnumerable myAL ) {
System.Collections.IEnumerator myEnumerator =
myAL.GetEnumerator();
while ( myEnumerator.MoveNext() )
Console.Write( "\t{0}", myEnumerator.Current );
Console.WriteLine();
}
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What is decimal in c#?
What is tuple in c#?
what is a structure in c#
What is stringreader in c#?
What is mvc pattern in c#?
Give an example of a directcast.
What are sessions in c#?
What is the difference between dispose() and finalize() methods in c#?
Explain the difference between event and a delegate in c#?
What do you mean by for each loop?
How to handle exceptions that are raised in a component?
Explain about Threading Types.
What is the function of .IsDescendent()?
Can c# inherit multiple classes?
What is the difference between dynamic type variables and object type variables in c#?