Hi Folks,
I am Beginner to C#. actually i attended the interview. they asking the question like that..
class A
{
public class A()
{
int a;
int b;
public int CalCum()
{
Return a+b;
}
}
in the above program a=10, b=20. i have few questions these are given below
1) How to call the constructor and pass the arguments?
2) How to use the arraylist in the program?
3) How to Pass the arguments by using Arraylist and show result?
Please help me. how to solve this secenrio? can anyone help for me

Thirupathi vPosted Oct 29, 2008, 6:52 AM
AlanPosted Oct 29, 2008, 6:22 AM
Check this out:
using System;
using System.Collections; // needed for ArrayList
class Program
{
static void Main()
{
A a = new A(10, 20);
int total = a.CalSum();
Console.WriteLine("The sum using the constructor is " + total);
A a2 = new A();
ArrayList al = new ArrayList();
al.Add(10);
al.Add(20);
a2.SetParameters(al);
int total2 = a2.CalSum();
Console.WriteLine("The sum using the arraylist is " + total2);
Console.ReadLine(); // to pause before exiting
}
}
public class A
{
int a;
int b;
// constructor with no parameters
public A()
{
}
// constructor with two parameters
public A(int a, int b)
{
this.a = a;
this.b = b;
}
//using arraylist to pass arguments
public void SetParameters(ArrayList al)
{
// in practice you'd need some error checking here
this.a = (int)al[0];
this.b = (int)al[1];
}
public int CalSum()
{
return a+b;
}
}