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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
ShankeyRank #972 · 2.1K reputationPosted Sep 6, 2010, 2:25 AM EDT
Please clarify, You want to create an array of class object ? right?
ganesh dutt pandey12 reputationPosted Sep 6, 2010, 2:51 AM EDT
ShankeyRank #972 · 2.1K reputationPosted Sep 6, 2010, 3:05 AM EDT
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";
}
}
}
Shahan AyyubRank #5,163 · 309 reputationPosted Dec 19, 2010, 10:14 AM EST
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
Sam HobbsRank #107 · 20.5K reputationPosted Dec 19, 2010, 1:15 PM EST