You are on page 1of 26

Module 4

Properties:
• Set Accessor: It will specify the assignment of a value to a private field in a
property. It returns a single value and it specifies the write-only property.

Example:
class Geeks {

// Declare roll_no field


private int roll_no;

// Declare roll_no property


public int Roll_no
{
set
{
roll_no = value;
}
}
}

• Read-Write Property:
• Auto Implemented Properties: (optional)

o/p
INDEXERS IN C#:
Syntax 2:
Difference between Array and Array list:
GENERICS IN C#

o/p;
COLLECTIONS IN C#:
Collections are similar to Arrays, it provides a more flexible way of working with
a group of objects.

In arrays, you would have noticed that you need to define the number of
elements in an array beforehand. This had to be done when the array was
declared.

But in a collection, you don't need to define the size of the collection
beforehand. You can add elements or even remove elements from the collection
at any point of time. This chapter will focus on how we can work with the
different collections available in C#.
o/p:
Constructors:
o/p:

NOTE: In collection initializer hash set program we don’t use add method, we
declare at the time of hash set initialization.
Methods:
o/p:
Ex:
o/p:
Methods:

Ex:
o/p:
INSERT NODE/KEY IN A BINARY TREE:

Program ex:
struct node* insert(struct node* root, int key)
{
// Base Cases: root is null or key is present at root
if (root == NULL || root->key == key)
return root;

// Key is greater than root's key


if (root->key < key)
return search(root->right, key);

// Key is smaller than root's key


return search(root->left, key);
}

------------------------END-------------------------------

You might also like