doubt

  • Thread starter Thread starter nallamalah
  • Start date Start date
N

nallamalah

how to decalre arraylists in csharp
i gave it like this iam getting error
using System;
using System.Collections;
public class aldemo
{
static void Main()
{
Arraylist al=new Arraylist;
al.add("v1");
al.add("v2");
al.add("v3");
Console.WriteLine(al[2]);
}
}

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
Hi Haritha,

The ArrayList stores object references of everything you put inside.
You will have to cast it back to its original type.

object o = al[2];
string s = (string)o;

or

Console.WriteLine((string)al[2]);
 
It is ArrayList, not Arraylist (note the char-casing). Also, () should be
present after the ArrayList (when declared using new keyword) as in:
ArrayList al = new ArrayList();

HTH.

how to decalre arraylists in csharp
i gave it like this iam getting error
using System;
using System.Collections;
public class aldemo
{
static void Main()
{
Arraylist al=new Arraylist;
al.add("v1");
al.add("v2");
al.add("v3");
Console.WriteLine(al[2]);
}
}

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET
resources...
 
Back
Top