Hi All,
Please tell me how can i create an class type array?If any body have some example links than please forward to me?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sam HobbsPosted Dec 19, 2010, 6:15 PM
Shahan AyyubPosted Dec 19, 2010, 3:14 PM
Use List OR ArrayList instead of simple array when you don' know the size of array. So, every time call Add() method and become independent on array size problems. Here is an another approach/alternative for you:
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
namespace Regexpression
{
public class Student
{
public int ID;
public String Name;
public Student(int id, string name)
{
ID = id;
Name = name;
}
}
class TestProgram
{
static void Main(string[] args)
{
//for custom objects like Class Student
List
students.Add(new Student(1, "abc"));
students.Add(new Student(2, "xyz"));
//for type object
List
ShankeyPosted Sep 6, 2010, 7:05 AM
folowing is your code but dont forget to mark my answer as accepted :)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class school
{
public int studid;
public String studName;
}
class Program
{
static void Main(string[] args)
{
school [] objSchool = new school[2];
objSchool[0].studid = 1;
objSchool[0].studName = "Maninder";
objSchool[1].studid = 2;
objSchool[1].studName = "Jasvinder";
}
}
}
ganesh dutt pandeyPosted Sep 6, 2010, 6:51 AM
ShankeyPosted Sep 6, 2010, 6:25 AM
Please clarify, You want to create an array of class object ? right?