Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 32

.

NET LABORATORY—10MCA57

CONTENT
Sl Date Name of Program Page
No. No.

1 `Write a Program in C# to Check whether a number is Palindrome or not.

2 Write a Program in C# to demonstrate Command line arguments Processing.

3 Write a Program in C# to find the roots of Quadratic Equation.

4 Write a Program in C# to demonstrate boxing and unBoxing

5 Write a Program in C# to implement Stack operations.

6 Write a program to demonstrate Operator overloading.

7 Write a Program in C# to find the second largest element in a single


dimensional array.
8 Write a Program in C# to multiply to matrices using Rectangular arrays.

9 Find the sum of all the elements present in a jagged array of 3 inner arrays.

10 Write a program to reverse a given string using C#.

11 Using Try, Catch and Finally blocks write a program in C# to demonstrate


error handling.
12 Design a simple calculator using Switch Statement in C#.

13 Demonstrate Use of Virtual and override key words in C# with a simple


program.
14 Implement linked lists in C# using the existing collections name space.

15 Write a program to demonstrate abstract class and abstract methods in C#.

16 Write a program in C# to build a class which implements an interface which


is already existing.
17 Write a program to illustrate the use of different properties in C#.

18 Demonstrate arrays of interface types with a C# program

Teacher Sign……………………………………………….

1
.NET LABORATORY—10MCA57

1. ``Write a Program in C# to Check whether a number is Palindrome or not.

Program:

using System;
using System.Collections.Generic;
using System.Text;

namespace LABPROGRAMS
{
class PALINDROME1
{
public static void Main(string[] args)
{

int n, rev = 0, rem, p;


Console.WriteLine("PROGRAM TO CHECK GIVEN INPUT NO IS
PALINDROME OR NOT");

Console.WriteLine("\n\nEnter n value");
n = int.Parse(Console.ReadLine());
p = n;

while (n > 0)
{
rem = n % 10;
n = n / 10;
rev = (rev * 10) + rem;
}

if (p == rev)
Console.WriteLine("The value {0} is palindrome", rev);
else
Console.WriteLine("The value {0} is not palindrome", rev);
Console.ReadLine();
}

2.Write a Program in C# to demonstrate Command line arguments Processing.

2
.NET LABORATORY—10MCA57

Program:
using System;
using System.Collections.Generic;
using System.Text;

namespace LABPROGRAMS
{
class CMDLINE2
{
static void Main(string[] args)
{

int n, i;
Console.WriteLine("PROGRAM TO IMPLEMENT COMMAND LINE
ARGUMENTS\n\n");

if (args.Length == 0)
{
Console.WriteLine("NO ARGUMENTS SUBMITTED");
Console.ReadLine();
}

for (i = 0; i < args.Length; i++)


{
n = int.Parse(args[i].ToString());
Console.WriteLine("The square of the given input value {0} is :{1}", n, n * n);
}
Console.ReadLine();

}
}
}

3
.NET LABORATORY—10MCA57

3.Write a Program in C# to find the roots of Quadratic Equation.

Program:
using System;

namespace C3
{
class Program
{
static void Main(string[] args)
{
int a, b, c,d;
double r1,r2;
Console.WriteLine("Let the quadratic equation is ax2+bx+c");
Console.WriteLine("Enter a ->");
a=int.Parse (Console.ReadLine());
Console.WriteLine("Enter b ->");
b = int.Parse(Console.ReadLine());
Console.WriteLine("Enter c ->");
c = int.Parse(Console.ReadLine());
d = (b * b) - 4 * a * c;
if (d > 0)
{
Console.WriteLine("Roots will be real numbers");
r1 = (double)(-b + Math.Sqrt(d)) / 2 * a;
r2 = (double) (-b - Math.Sqrt(d)) / 2 * a;
Console.WriteLine("root1={0}", r1);
Console.WriteLine("root2={0}", r2);
}
else
{
Console.WriteLine(" Roots will be imaginary");
}
Console.ReadLine();
}
}
}

4
.NET LABORATORY—10MCA57

4. Write a Program in C# to demonstrate boxing and unBoxing.

Program:

using System;

namespace C4
{
class Program
{
static void Main(string[] args)
{
int i = 8;
object o = i; // boxing
int j = (int)o; // unboxing
Console.WriteLine("o={0}", o);
Console.WriteLine("j={0}", j);
Console.ReadLine();
}
}
}

5
.NET LABORATORY—10MCA57

5. Write a Program in C# to implement Stack operations.

Program:
using System;
namespace C5
{
class stack
{
public int[] stck = new int[50];
public int top;
public void push(int item)
{
if (top == stck.Length - 1)
Console.WriteLine("Stack is full.");
else
stck[++top] = item;
}
public int pop()
{
if (top < 0)
{
Console.WriteLine("Stack underflow.");
return 0;
}
else
return stck[top--];
}
public void display()
{
Console.WriteLine("Items of the stack are ->");
for (int i = 1; i <= top; i++)
Console.WriteLine(" {0}",stck[i]);
}
}
class Program
{
static void Main(string[] args)

6
.NET LABORATORY—10MCA57

{
int top = -1;
stack s1 = new stack();
Console.WriteLine("1.Push");
Console.WriteLine("2.Pop");
Console.WriteLine("3.Display");
Console.WriteLine("4.Exit");
while (true)
{
Console.WriteLine("Enter your choice ->");
int ch = int.Parse(Console.ReadLine());
switch (ch)
{
case 1:
Console.WriteLine("Enter the item ->");

s1.push(int.Parse(Console.ReadLine()));
Console.WriteLine("Item inserted");
break;
case 2:
Console.WriteLine("Popped item={0}", s1.pop());
break;
case 3:
s1.display();
break;
default:
Console.WriteLine("Wrong Choice");
break;
}
}

}
}

7
.NET LABORATORY—10MCA57

6. Write a program to demonstrate Operator overloading.

Program:
using System;
namespace C6
{
class Complex
{
private int x;
private int y;
public Complex()
{
}
public Complex(int i, int j)
{
x = i;
y = j;
}
public void ShowXY()
{
Console.WriteLine("{0} {1}",x,y);
}
public static Complex operator -(Complex c)
{
Complex temp = new Complex();
temp.x = -c.x;

8
.NET LABORATORY—10MCA57

temp.y = -c.y;
return temp;
}
}
class Program
{
static void Main(string[] args)
{
Complex c1 = new Complex(90, 50);
c1.ShowXY(); // displays 10 & 20
Complex c2 = new Complex();
c2.ShowXY(); // displays 0 & 0
c2 = -c1;
c2.ShowXY(); // diapls -10 & -20
Console.ReadLine();
} }}

7. Write a Program in C# to find the second largest element in a single dimensional array.

Program:

using System;
using System.Collections.Generic;
using System.Text;

namespace LABPROGRAMS
{

class SNDLARGE7
{

9
.NET LABORATORY—10MCA57

static void Main(string[] args)


{
int n, i, max = -32767, smax = -32767;
int[] a = new int[10];
Console.WriteLine("TO FIND SECOND MAXIMUM VALUE IN AN ARRAY");
Console.WriteLine("\n\nEnter the no.of elements");
n = Int32.Parse(Console.ReadLine());

for (i = 0; i < n; i++)


{
Console.Write("Enter the value of a[{0}]:", i);
a[i] = Int32.Parse(Console.ReadLine());
}

for (i = 0; i < n; i++)


{

if (a[i] >= max)


max = a[i];
}

for (i = 0; i < n; i++)


{
if ((a[i] < max) && (smax < a[i]))
smax = a[i];
}
Console.WriteLine("Second Maximum value in an array is : {0}", smax);
Console.ReadLine();
}
}
}

10
.NET LABORATORY—10MCA57

8. Write a Program in C# to multiply to matrices using Rectangular arrays.

Program:

using System;
using System.Collections.Generic;
using System.Text;

namespace LABPROGRAMS
{
class MATRIXMUL8
{
static void Main(string[] args)
{

int r1, c1, r2, c2, i, j, k;


int [,]a = new int[4, 4];
int [,]b = new int[4, 4];
int [,]c = new int[4, 4];
Console.WriteLine("PROGRAM TO IMPLEMENT MATRIX MULTIPLICATION");
Console.WriteLine("\n\nEnter the rows and columns size of A matrix");
r1 = Int32.Parse(Console.ReadLine());
c1 = Int32.Parse(Console.ReadLine());
Console.WriteLine("Enter the rows and columns size of B matrix");
r2 = Int32.Parse(Console.ReadLine());
c2 = Int32.Parse(Console.ReadLine());

if (c1 != r2)
{
Console.WriteLine("columns of A matrix and Rows of B matrix are not equal");

11
.NET LABORATORY—10MCA57

Console.ReadLine();
Environment.Exit(0);
}

Console.WriteLine("Enter A MATRIX elements 1 by 1");


for (i = 0; i < r1; i++)
{
for (j = 0; j < c1; j++)
{
a[i, j] = Int32.Parse(Console.ReadLine());
}
}

Console.WriteLine("Enter B MATRIX elements 1 by 1");


for (i = 0; i < r2; i++)

{
for (j = 0; j < c2; j++)
{
b[i, j] = Int32.Parse(Console.ReadLine());
}
}

for (i = 0; i < r1; i++)


{
for (j = 0; j < c2; j++)
{
for (k = 0; k < r2; k++)
{
c[i, j] = c[i, j] + (a[i, k] * b[k, j]);
}
}
}

Console.WriteLine("Result matrix");
Console.WriteLine("*************");
for (i = 0; i < r2; i++)
{
for (j = 0; j < c2; j++)
{
Console.Write("{0}\t", c[i, j]);
}
Console.WriteLine();
}

12
.NET LABORATORY—10MCA57

Console.ReadLine();

}
}
}

9. Find the sum of all the elements present in a jagged array of 3 inner arrays.
Program:

using System;

namespace C9
{
class Program
{
static void Main(string[] args)
{
int[][] jagged = new int[3][];
int sum=0;
jagged[0] = new int[2] { 5, 6 };
jagged[1] = new int[3] { 2, 3, 6 };
jagged[2] = new int[3] { 7, 0,1 };

13
.NET LABORATORY—10MCA57

for (int i = 0; i < jagged.Length; i++)


{
for (int j = 0; j < jagged[i].Length; j++)
sum = sum + jagged[i][j];
}
Console.WriteLine("sum={0}", sum);
}

}
}

10. Write a program to reverse a given string using C#.

Program:

using System;
using System.Collections.Generic;
using System.Text;

namespace LABPROGRAMS
{
class STRINGREV10
{
static void Main(string[] args)
{

14
.NET LABORATORY—10MCA57

string s;
char[] d = new char[100];
int len, j = 0;

Console.WriteLine("PROGRAM TO REVERSE A STRING");


Console.WriteLine("\n\n\nEnter the string");
s = Console.ReadLine();
len = s.Length;

//Console.WriteLine("The string length is:{0}", len);


while (len > 0)
{
len = len - 1;
d[j] = s[len];
j++;
}

Console.WriteLine("\nThe given input string is:" + s);


Console.WriteLine("\nThe Reversed string is:");
Console.WriteLine(d);
Console.ReadLine();
}
}
}

15
.NET LABORATORY—10MCA57

11. Using Try, Catch and Finally blocks write a program in C# to demonstrate error handling.
Program:
using System;
namespace C11
{
class Program
{
static void Main(string[] args)
{
while (true)
{
try
{
string userInput;
Console.Write("Input a number between 0 and 5 " + "(or just hit return to exit) > ");
userInput = Console.ReadLine();
if (userInput == "")
{
break;
}
int index = Convert.ToInt32(userInput);
if (index < 0 || index > 5)
{
throw new IndexOutOfRangeException("You typed in " + userInput);
}
Console.WriteLine("Your number was " + index);
}
catch (IndexOutOfRangeException ex)
{
Console.WriteLine("Exception: " + "Number should be between 0 and 5. {0}",
ex.Message);
}
catch (Exception ex)
{
Console.WriteLine("An exception was thrown. Message was: {0}", ex.Message);
}
catch
{
Console.WriteLine("Some other exception has occurred");

16
.NET LABORATORY—10MCA57

}
finally
{
Console.WriteLine("Thank you");
}
}

}
}
}

12. Design a simple calculator using Switch Statement in C#.

Program:

using System;
using System.Collections.Generic;
using System.Text;

namespace Calculator
{
class Program
{
double num1, num2;
char option, choice;
double Result;
public void Number()
{
for (; ; )
{
Console.WriteLine("Enter the first number :");
17
.NET LABORATORY—10MCA57

num1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the Second number :");
num2 = Convert.ToDouble(Console.ReadLine());

Console.WriteLine("Main Menu");
Console.WriteLine("1. Addition");
Console.WriteLine("2. Subtraction");
Console.WriteLine("3. Multiplication");
Console.WriteLine("4. Division");

Console.WriteLine("Enter the operation you want to perform");


option = Convert.ToChar(Console.ReadLine());

switch (option)
{
case '1': Result = num1 + num2;
Console.WriteLine("The Result of Addition :{0}", Result);
break;
case '2': Result = num1 - num2;
Console.WriteLine("The Result of Subtraction :{0}", Result);
break;
case '3': Result = num1 * num2;
Console.WriteLine("The Result of Multiplication :{0}", Result);
break;
case '4': Result = num1 / num2;
Console.WriteLine("The Result of Division :{0}", Result);
break;
default: Console.WriteLine("Invalid Option");
break;

}
Console.WriteLine("Do u want to Continue? [y/n]");
choice = Convert.ToChar(Console.ReadLine());
if (choice == 'n')
break;
}

}
}
class ClassMain
{
static void Main(string[] args)
{
Program calc = new Program();
calc.Number();

18
.NET LABORATORY—10MCA57

}
}
}

13. Demonstrate Use of Virtual and override key words in C# with a simple program.

Program:

using System;
using System.Collections.Generic;
using System.Text;

namespace Virtual_and_Overide
{
class Department
{
public virtual void AcceptDeptDetails()
{

19
.NET LABORATORY—10MCA57

Console.WriteLine("Here U have to enter Departments Details");


}
public virtual void DisplayDeptDetails()
{
Console.WriteLine("Here it will display Departments Details");
}
}
class MCA : Department
{
string HODName,temp1;
int NumOf_Faculties, NumOf_students;
public override void AcceptDeptDetails()
{
Console.WriteLine("\n MCA DETAILS \n");
Console.WriteLine("Enter HOD Name :");
HODName = Console.ReadLine();
Console.WriteLine("Enter No. of Faculties :");
temp1 = Console.ReadLine();
if (temp1 != "")
NumOf_Faculties = Convert.ToInt32(temp1);
Console.WriteLine("Enter No. of Students :");
temp1 = Console.ReadLine();
if (temp1 != "" )
NumOf_students = Convert.ToInt32(temp1);

}
public override void DisplayDeptDetails()
{
Console.WriteLine("Name of the HOD : {0}", HODName);
Console.WriteLine("No. of Faculties : {0}", NumOf_Faculties);
Console.WriteLine("No. of Students : {0}", NumOf_students);
}
}
class MBA : Department
{
string HODName,temp1;
int NumOf_Faculties, NumOf_students;
public override void AcceptDeptDetails()
{
Console.WriteLine("\n MBA DETAILS \n");
Console.WriteLine("Enter HOD Name :");
HODName = Console.ReadLine();
Console.WriteLine("Enter No. of Faculties :");
temp1 = Console.ReadLine();
if (temp1 != "")
NumOf_Faculties = Convert.ToInt32(temp1);

20
.NET LABORATORY—10MCA57

Console.WriteLine("Enter No. of Students :");


temp1 = Console.ReadLine();
if(temp1!="")
NumOf_students = Convert.ToInt32(temp1);

}
public override void DisplayDeptDetails()
{
Console.WriteLine("Name of the HOD : {0}", HODName);
Console.WriteLine("No. of Faculties : {0}", NumOf_Faculties);
Console.WriteLine("No. of Students : {0}", NumOf_students);
}
}
class Implement
{
public void callAcceptFunction(Department clg)
{
clg.AcceptDeptDetails();
}
public void callDisplayFunction(Department clg)
{
clg.DisplayDeptDetails();
}

}
class Program
{
static void Main(string[] args)
{
Implement imp = new Implement();
MCA MC = new MCA();
MBA MB = new MBA();
imp.callAcceptFunction(MC);
imp.callDisplayFunction(MC);
Console.WriteLine();
imp.callAcceptFunction(MB);
imp.callDisplayFunction(MB);
Console.ReadLine();
}
}
}

21
.NET LABORATORY—10MCA57

14. Implement linked lists in C# using the existing collections name space.

Program:

using System;
using System.Collections.Generic;
using System.Text;

namespace LinkedListEx
{
class Program
{
static void Main(string[] args)
{
int option;
char choice;
int item, key;
LinkedList<int> List = new LinkedList<int>();
try
{

22
.NET LABORATORY—10MCA57

for (; ; )
{
Console.WriteLine("Main Menu");
Console.WriteLine("1. Add the node from the beginning");
Console.WriteLine("2. Add the node from the Last");
Console.WriteLine("3. Add the node after the key Node");
Console.WriteLine("4. Delete the node from the beginning");
Console.WriteLine("5. Delete the node from Last");
Console.WriteLine("6. search the Node");
Console.WriteLine("7. display the nodes in the linked list");

Console.WriteLine("Enter the Option :[1-7]");


option = Convert.ToInt32(Console.ReadLine());
switch (option)
{
case 1: Console.WriteLine("Enter Value to enter :");
item = Convert.ToInt32(Console.ReadLine());
List.AddFirst(item); break;

case 2: Console.WriteLine("Enter Value to enter :");


item = Convert.ToInt32(Console.ReadLine());
List.AddLast(item); break;

case 3: Console.WriteLine("Enter key value :");


key = Convert.ToInt32(Console.ReadLine());
LinkedListNode<int> current = List.FindLast(key);

if (List.FindLast(key) != null)
{
Console.WriteLine("Enter Value to enter :");
item = Convert.ToInt32(Console.ReadLine());
List.AddAfter(current, item); break;
}
else
{
Console.WriteLine("Entered Key value is not found ");
break;
}

case 4:
if (List.First == null)
{
Console.WriteLine("linked list is empty");
break;
}
else

23
.NET LABORATORY—10MCA57

{
List.RemoveFirst();
break;
}

case 5: LinkedListNode<int> Lst = List.Last;


if (List.Last == null)
{
Console.WriteLine("linked list is empty");
break;
}
else
{
List.RemoveLast();
break;
}

case 6: Console.WriteLine("Enter key value to search :");


key = Convert.ToInt32(Console.ReadLine());

if (List.FindLast(key) == null)
{
Console.WriteLine("Entered Key value is not found ");
break;
}
else
{
Console.WriteLine("Key value is found");
break;
}

case 7: Console.WriteLine("the values in the Linked List :");


foreach (int temp in List)
{
Console.Write(temp + " ");
}
Console.WriteLine();
break;

default: Console.WriteLine("Invalid Input :"); break;

}
Console.WriteLine("Do u want to Continue [y/n] :");
choice = Convert.ToChar(Console.ReadLine());
if (choice == 'n')

24
.NET LABORATORY—10MCA57

break;
}
}
catch
{
Console.WriteLine("Invalide Input");
Console.ReadLine();
}

}
}}

25
.NET LABORATORY—10MCA57

15. Write a program to demonstrate abstract class and abstract methods in C#.

Program:

using System;
using System.Collections.Generic;
using System.Text;

namespace Abstract_Class_and_Method
{
public abstract class Furniture
{
protected string color;
protected int width;
protected int height;
public abstract void Accept();
public abstract void Display();
}
class Bookshelf : Furniture
{
private int numOf_shelves;
public override void Accept()
{
string str1, str2, str3;
Console.WriteLine("ENTER VALUES FOR BOOKSHELF");
Console.WriteLine("Enter Color ");
color = Console.ReadLine();
Console.WriteLine("Enter Width ");
str1 = Console.ReadLine();
width = Convert.ToInt32(str1);
Console.WriteLine("Enter Height");
str2 = Console.ReadLine();
height = Convert.ToInt32(str2);
Console.WriteLine("Enter No. of Shelves ");
str3 = Console.ReadLine();
numOf_shelves = Convert.ToInt32(str3);
}
public override void Display()
{
Console.WriteLine("DISPLAYING VALUES FOR BOOKSHELF");
Console.WriteLine("Color is {0}", color);
Console.WriteLine("Width is {0}", width);
Console.WriteLine("Height is {0}", height);
Console.WriteLine("Number of shelves are {0}", numOf_shelves);
}
}

26
.NET LABORATORY—10MCA57

class Chair : Furniture


{
private int numOf_legs;
public override void Accept()
{
string str1, str2, str3;
Console.WriteLine("ENTER VALUES FOR CHAIR");
Console.WriteLine("Enter Color ");
color = Console.ReadLine();
Console.WriteLine("Enter Width ");
str1 = Console.ReadLine();
width = Convert.ToInt32(str1);
Console.WriteLine("Enter Height");
str2 = Console.ReadLine();
height = Convert.ToInt32(str2);
Console.WriteLine("Enter No. of legs in a chair ");
str3 = Console.ReadLine();
numOf_legs = Convert.ToInt32(str3);
}
public override void Display()
{
Console.WriteLine("DISPLAYING VALUES FOR CHAIR");
Console.WriteLine("Color is {0}", color);
Console.WriteLine("Width is {0}", width);
Console.WriteLine("Height is {0}", height);
Console.WriteLine("Number of legs are {0}", numOf_legs);
}
}
class Program
{
static void Main(string[] args)
{
Bookshelf bk = new Bookshelf();
Chair cr = new Chair();
bk.Accept();
bk.Display();
cr.Accept();
cr.Display();
Console.ReadLine();
}
}
}

27
.NET LABORATORY—10MCA57

16. Write a program in C# to build a class which implements an interface which is already
existing.

Program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace InterfaceImplementation
{
public interface calc
{
void Addition(int a,int b);
void Subtraction(int a, int b);
}
class interfaceUser : calc

28
.NET LABORATORY—10MCA57

{
public void Addition(int a,int b)
{
Console.WriteLine("Result of Addition :{0}", a + b);
}
public void Subtraction(int a, int b)
{
Console.WriteLine("Result of Subtraction :{0}", a - b);
} }
class Program
{
static void Main(string[] args)
{
interfaceUser iUser = new interfaceUser();
int a = 0, b = 0;
string temp1,temp2;
Console.WriteLine("Enter first value :");
temp1 = Console.ReadLine();
if(temp1!="")
a = Convert.ToInt32(temp1);

Console.WriteLine("Enter second value :");


temp2 = Console.ReadLine();
if (temp2 != "")
b = Convert.ToInt32(temp2);

iUser.Addition(a,b);
iUser.Subtraction(a,b);
Console.ReadLine();
}
}
}

29
.NET LABORATORY—10MCA57

17. Write a program to illustrate the use of different properties in C#.

Program:

using System;
using System.Collections.Generic;
using System.Text;

namespace PropertiesEx
{
class Favorites
{
private string color;
private string player;
private string company;

public string clr


{
get
{
return color;
}
set
{
color = value;
}
}
public string plr
{
get
{
return player;
}
}
public Favorites(string colr,string plyr,string comp)
{
color = colr;
player = plyr;
company = comp;
}
public void Display()
{
Console.WriteLine("My Favorite Color is :{0}", color);
Console.WriteLine("My Favorite Player is :{0}", player);
Console.WriteLine("My Favorite Company is :{0}", company);
}

30
.NET LABORATORY—10MCA57

class Program
{
static void Main(string[] args)
{
string colr, playr, comp;
Console.WriteLine("Enter u r Favorite color :");
colr=Console.ReadLine();
Console.WriteLine("Enter u r Favorite Player :");
playr = Console.ReadLine();
Console.WriteLine("Enter u r Favorite Company :");
comp = Console.ReadLine();

Favorites frt = new Favorites(colr, playr, comp);


Console.WriteLine("\n\n After assigning the values using constructor\n");
frt.Display();

Console.WriteLine("\n \n Enter u r Favorite color :");


frt.clr = Console.ReadLine();
Console.WriteLine("\n After assigning the value to Color in main function\n");
frt.Display();
Console.WriteLine("\n In Main function My Favorite Color is :{0}", frt.clr);

Console.WriteLine("\n In Main function My Favorite Player is :{0}", frt.plr);

Console.ReadLine();

}
}
}

31
.NET LABORATORY—10MCA57

18. Demonstrate arrays of interface types with a C# program


Program:

using System;
using System.Collections;
public class MyComparer : IComparer {
public int Compare(object aobj, object bobj) {
int a = (int)aobj;
int b = (int)bobj;
return (a < b ? 1 : a == b ? 0 : -1);
}
}
public class SortDemo {
public static void Main() {
const int N = 14;
ArrayList list = new ArrayList();
for (int i = 0; i < N; i++)
list.Add(i);
list.Sort();
for (int i = 0; i < N; i++)
Console.Write(list[i] + " ");
Console.WriteLine();
list.Sort(new MyComparer());
for (int i = 0; i < N; i++)
Console.Write(list[i] + " ");
Console.WriteLine();
}
}

32

You might also like