Adv C#
Programming

1. Introduction to .NET and C# 2. Points to keep in mind for pyramid 3. C# Pyramid Program Example for type 1 4. C# Pyramid Program Example for type 2 5. C# Pyramid Programs on Type 3 6. C# Pyramid Programs of type 4 7. C# Pyramid Programs of type 5 8. Classes and Objects 9. Recursive functions 10. Constructors in C# 11. Destructor 12. Method Overloading 13. Constructor Overloading 14. Inheritance in C# 15. Interface in C# 16. Method Overriding 17. readonly and sealed keyword in C# 18. Exception Handling 19. Delegates 20. Multicast Delegates 21. Events 22. Structure 23. Threads 24. Working with Threads 25. Thread Life Cycle 26. Introducing Multithreading 27. Advantage and limitation of multithreading 28. Thread priority 29. Properties 30. Collections 31. ArrayList Class 32. Hastable Class 33. SortedList 34. Stack 35. Queue Class 36. Generics 37. Unsafe code 38. C# Networking 39. Prgs for Science and Engineer 40. Prg to use alias 41. Prg to count minors and majors using array 42. Prg for sum up of two array in third array 43. Prg to show boxing and unboxing 44. Prg for type casting from byte to int 45. Prg to find area of circle 46. Prg to find cube root of entered number 47. Prg for digit manipulation 48. Prg for printing a reverse triangle 49. Prg to show case and goto fall through 50. Prg to show use of foreach loop 51. Prg for adding 2 numbers 52. Prg to show jagged array 53. Prg to show different methods of Array 54. Prg to print number Pyramid 55. Prg to show entered string is palindrome or not 56. Prg to show entered number is prime or not 57. Prg to show different methods of StringBuilder 58. Prg to show different methods of String 59. Prg for appending a string using StringBuilder 60. Prg to show appending a string with numeric type data using StringBuilder 61. Prg to show use of ArrayList 62. Prg to pass an array as a parameter to a function for finding out a prime number 63. Prg to show the constant member 64. Prg for showing destructor 65. Prg for sum up and reversing the entered number 66. Prg for enum type conversation 67. Prg to show sum of first fifty even and odd number 68. Prg to find the factorial of entered number 69. Prg for iterating each element of array using foreach loop 70. Prg to show array position and value 71. Prg to show how to insert and remove string using StringBuilder 72. Prg to show how to join the string 73. Prg to show the value of sin 90 74. Prg to enter two number and find max 75. Prg to show padding 76. Prg to show entered number is prime or not 77. Prg to show private constructor 78. Prg to show how to use getter and setter property 79. Prg using out parameter 80. Prg to count the number of spaces and words in a String 81. Prg to show how to use Split method 82. Prg to create binary triangle 83. Prg to create dule star triangle 84. Prg to create triangle 85. Prg to show use of EndsWith and StartsWith method of string 86. Prg for static constructor 87. Prg to show how to use insert method 88. Prg to sort a string 89. Prg to store student name and roll no using structure 90. Prg to show how to use delegate 91. Prg to calculate depreciation 92. Prg for calculating Economic order cost and time between order 93. Prg to find radius of circle 94. Prg to sum up odd numbers from 0 to 20 95. Prg to calculate simple interest 96. Prg to categorise student on base of there marks range where marks are stored in array 97. Prg to create triangle on console screen 98. Prg to print sin theta, cos theta and tan theta from 0.1 to 1.0 angle in radians 99. Prg to demonstrate variables 100. Prg to illustrate the differences between int and double 101. Prg to show exception handling using try.. catch block 102. Prg to demonstrate how to use interface 103. Prg to print number triangle 104. Prg to demonstrate structure 105. Prg to test exception 106. Prg to count number of spaces and words in a entered string 107. Prg to demonstrate ref parameter 108. Prg to print a matrix table from 1 to 10 109. Prg to display 2 D array elements position in matrix form 110. Prg to count number of adult and children 111. Prg to print pascal triangle 112. Prg to demonstrate stringbuilder and its method 113. Prg to reverse a string 114. Prg for string sorting 115. Interview Question & Answer part 1 116. Interview Question & Answer part 2 117. Interview Question & Answer part 3 118. Interview Question & Answer part 4 119. Interview Question & Answer part 5 120. Interview Question & Answer part 6 121. Interview Question & Answer part 7 122. Interview Question & Answer part 8 123. Interview Question & Answer part 9 124. Interview Question & Answer part 10 125. Interview Question & Answer part 11 126. Interview Question & Answer part 12 127. Interview Question & Answer part 13 128. Interview Question & Answer part 14 129. Interview Question & Answer part 15
Pr.Pg Next Pg

ArrayList Class tutorials

  • It represents an ordered collection of an object that can be indexed individually.

  • It is basically an alternative to an array. However unlike array you can add and remove items from a list at a specified position using an index and the array resizes itself automatically.

  • It also allow dynamic memory allocation, adding, searching and sorting items in the list.

  • Below table describes the properties of the ArrayList class:

 

Property

Description

Capacity

Gets or sets the number of elements that the ArrayList can contain.

Count

Gets the number of elements actually contained in the ArrayList.

IsFixedSize

Gets a value indicating whether the ArrayList has a fixed size.

IsReadOnly

Gets a value indicating whether the ArrayList is read-only.

Item

Gets or sets the element at the specified index.

 

  • The below table describe the methods of ArrayList class:

 

S.N

Method Name & Purpose

1

public virtual int Add( object value ); 
Adds an object to the end of the ArrayList.

2

public virtual void AddRange( ICollection c ); 
Adds the elements of an ICollection to the end of the ArrayList.

3

public virtual void Clear();
Removes all elements from the ArrayList.

4

public virtual bool Contains( object item ); 
Determines whether an element is in the ArrayList.

5

public virtual ArrayList GetRange( int index, int count ); 
Returns an ArrayList which represents a subset of the elements in the source ArrayList.

6

public virtual int IndexOf(object);
Returns the zero-based index of the first occurrence of a value in the ArrayList or in a portion of it.

7

public virtual void Insert( int index, object value ); 
Inserts an element into the ArrayList at the specified index.

8

public virtual void InsertRange( int index, ICollection c ); 
Inserts the elements of a collection into the ArrayList at the specified index.

9

public virtual void Remove( object obj ); 
Removes the first occurrence of a specific object from the ArrayList.

10

public virtual void RemoveAt( int index ); 
Removes the element at the specified index of the ArrayList.

11

public virtual void RemoveRange( int index, int count ); 
Removes a range of elements from the ArrayList.

12

public virtual void Reverse();
Reverses the order of the elements in the ArrayList.

13

public virtual void SetRange( int index, ICollection c ); 
Copies the elements of a collection over a range of elements in the ArrayList.

14

public virtual void Sort();
Sorts the elements in the ArrayList.

15

public virtual void TrimToSize();
Sets the capacity to the actual number of elements in the ArrayList.

 

 

Example: Csharp program to demonstrate Arraylist

Sam Madam 

// Csharp program to demonstrate Arraylist

using System;

using System.Collections;

class Program

{

static void Main(string[] args)

{

int[] number = new int[10];

ArrayList al = new ArrayList();

Console.WriteLine("Adding some numbers in arraylist:");

for (int i = 0; i < 10; i++)

{

Console.Write("Enter any number : ");

number[i] = Int32.Parse(Console.ReadLine());

al.Add(number[i]);

}

Console.WriteLine("Capacity: {0} ", al.Capacity);

Console.WriteLine("Count: {0}", al.Count);

Console.Write("Content: ");

foreach (int i in al)

{

Console.Write(i + " ");

}

Console.WriteLine();

Console.Write("Sorted Content: ");

al.Sort();

foreach (int i in al)

{

Console.Write(i + " ");

}

Console.WriteLine();

}

}

 

Output

Adding some numbers in arraylist:

Enter any number : 1

Enter any number : 3

Enter any number : 5

Enter any number : 4

Enter any number : 6

Enter any number : 2

Enter any number : 9

Enter any number : 8

Enter any number : 10

Enter any number : 7

Capacity: 16

Count: 10

Content: 1 3 5 4 6 2 9 8 10 7

Sorted Content: 1 2 3 4 5 6 7 8 9 10

 


 

Example: Csharp program to manipulate character using ArrayList

Sam Madam 

// Csharp program to manipulate character using ArrayList

using System;

using System.Collections;

class ArrayListDemo

{

static void Main()

{

char[] ch = new char[5];

int i;

ArrayList al = new ArrayList();

Console.WriteLine("Initial number of elements: " + al.Count);

Console.WriteLine();

Console.WriteLine("Adding 5 character elements");

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

{

Console.Write("Enter any character : ");

ch[i] = char.Parse(Console.ReadLine());

al.Add(ch[i]);

}

Console.WriteLine("Number of elements: " +

al.Count);

Console.Write("Current contents: ");

for (i = 0; i < al.Count; i++)

Console.Write(al[i] + " ");

Console.WriteLine("\n");

Console.WriteLine("Removing 2 elements");

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

{

Console.Write("Enter a character to remove : ");

ch[i] = char.Parse(Console.ReadLine());

al.Remove(ch[i]);

}

Console.WriteLine("Number of elements: " + al.Count);

Console.Write("Contents: ");

foreach (char c in al)

{

Console.Write(c + " ");

}

Console.WriteLine("\n");

Console.WriteLine("Adding 20 more elements");

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

{

al.Add((char)('a' + i));

}

Console.WriteLine("Current capacity: " + al.Capacity);

Console.WriteLine("Number of elements after adding 20: " + al.Count);

Console.Write("Contents: ");

foreach (char c in al)

{

Console.Write(c + " ");

}

Console.WriteLine("\n");

Console.WriteLine("Change first three elements");

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

{

Console.Write("Enter character : ");

ch[i] = char.Parse(Console.ReadLine());

 

}

al[0] = ch[0];

al[1] = ch[1];

al[2] = ch[2];

Console.Write("Contents: ");

foreach (char c in al)

{

Console.Write(c + " ");

}

Console.WriteLine();

}

}

 

Output

Initial number of elements: 0

 

Adding 5 character elements

Enter any character : a

Enter any character : b

Enter any character : c

Enter any character : d

Enter any character : e

Number of elements: 5

Current contents: a b c d e

 

Removing 2 elements

Enter a character to remove : b

Enter a character to remove : d

Number of elements: 3

Contents: a c e

 

Adding 20 more elements

Current capacity: 32

Number of elements after adding 20: 23

Contents: a c e a b c d e f g h i j k l m n o p q r s t

 

Change first three elements

Enter character : x

Enter character : y

Enter character : z

Contents: x y z a b c d e f g h i j k l m n o p q r s t

Pr.Pg border                                              Next Pg