Академический Документы
Профессиональный Документы
Культура Документы
Declaration
Ex.:
a
1 2 3 4 5 6 7 8 9 10
for(int i=0;i<=9;i++)
{
a[i] = (i*3);
}
a
0 3 6 9 12 15 18 21 24 27
Initializing array
arr
1 2 3 4 5
month
jan feb Mar
string []month = new string[3];
month[0]="jan";
month[1] = "feb";
month[2] = "mar";
or
month[0] = new string();
month[1] = new string();
month[2] = new string();
or
for(int i=0;i<=2;i++) {
month[i] = new String();
}
or
month[0] = new string(“jan”);
month[1] = new string(“feb”);
month[2] = new string(“mar”);
arr
int [,]arr = {
{1,2,3},
{4,5,6},
{7,8,9}
};
1 2 3
4 5 6
7 8 9
Array of Objects:
class MyClass {
public int a;
public string s;
}
for(int i=0;i<=4;i++) {
objarr[i] = new MyClass(); //(Black Letters below)
}
Ref1 Object1
4 byte int 10 byte string
Ref2 Object2
4 byte int 10 byte string
Ref3 Object3
4 byte int 10 byte string
Ref4 Object4
4 byte int 10 byte string
Ref5 Object5
4 byte int 10 byte string
Functions:
Calling a function
myf(3);
Defining function
void myf(int x)
{
class MyClass
{
int a,b,c;
}
class YourClass
{
MyClass ref; // It is a reference will not get any memory
void myf()
{
MyClass a1 = new MyClass();
ref=a1;
//ref = new MyClass(); //memory allocation may be
done here
//a1 = new MyClass(); //allowed
}
}
A1
ref ref
A1
Exte
Ex.
object obj;
string str="pace bureau";
obj=(object) str;
string m=(string)obj;
Enumerators
enum gender
{
male=1,
female=10
};
Enum System.Drawing.Color {
Red = 0xFF000,
Green = 0x00FF00,
----------
};
enum gender g;
g =1; // gender.male;
FOREACH LOOP
foreach(ListItem x in dropdownlist1.items)
{
x.Text="r"+x.Text;
}
int []a = new int[10];
Foreach(int t in a) {
-----
}
e.g.
string temp=””;
string temp1=””;
for(int I=0;I<=dropdownlist1.items.count-1;I++) {
temp = dropdownlist1.items[I].Text;
temp1 = dropdownlist1.items[I].Value;
response.write(temp);
}
foreach(ListItem item in dropdownlist1.items) {
temp = item.Text;
temp1 = item.Value;
response.write(temp);
}
Namespaces in C#
Namespace is a collection of classes which work as a library for
other programs. They are used for creating a new scope where
different visibilities can be achieved. We can create our own
namespace as follows
namespace <name of namespace>
{
Classes..
}
Using namespaces:
For using the namespace in a program we use the “using”
keyword as follows:
Ex.
namespace myns
{
public class Calculator
{
double a,b,c;
public void get(int a1, int b1)
{
a=a1;
b=b1;
}
-------
}
-----------
public namespace myns1
{
------
}
}