Friday, 21 December 2012 13:56

Array of objects in c# programming

Written by 
Rate this item
(0 votes)

There is a big difference in creating array of
objects in c# from c++,java.creating an array
of objects involves two step.

c# is a object oriented programming language.
therefore In c# an array of objects is considered
an object.so after declaring array of objects,
each elements of the array must be created.but
in c++ and java it's done in different ways.

as an example below shows the code snippet to
create array of obj: in c# -

first we declare the array of objects-
ClassName arr=new ClassName[10];
where ClassName is the class name.

now the following codes shows how to create
each individual part or the array of objects.
for(int i=0,i<10;i++) arr[i]=new ClassName();

where ClassName() is the constructor of the
Object Class.

the full program is written below-

class ClassName{
private members declaration and methods
declaration here..
}
public static void main(){
ClassName arr=new ClassName[10];
for(int i=0,i<10;i++) arr[i]=new ClassName()
}

Read 4075 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.