0% found this document useful (0 votes)
9 views

Chapter 3- Data Structures in C#

This document is a compilation of Chapter Three from a course on Event-Driven Programming at Haramaya University, focusing on data structures in C#. It covers various data structures such as arrays, strings, and structures in C#, including their definitions, properties, and common operations. The document provides examples and explanations of how to manipulate these data structures using C# programming language features.

Uploaded by

Teddy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Chapter 3- Data Structures in C#

This document is a compilation of Chapter Three from a course on Event-Driven Programming at Haramaya University, focusing on data structures in C#. It covers various data structures such as arrays, strings, and structures in C#, including their definitions, properties, and common operations. The document provides examples and explanations of how to manipulate these data structures using C# programming language features.

Uploaded by

Teddy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

HARAMAYA UNIVERSITY

COLLEGE OF COMPUTING AND INFORMATICS


DEPARTMENT OF SOFTWARE ENGINEERING

EVENT-DRIVEN PROGRAMMING (Seng 5121)

CHAPTER THREE- DATA STRUCTURES IN C#

COMPILED BY: GIZACHEW B.


2 CONTENTS

 ARRAY

 STRING

 STRUCTURE

 LIST

 DICTIONARY
3
ARRAY … (1)
 An array stores a fixed-size collection of elements of the same type stored at sequential memory locations.

 Length of the array specifies the number of elements present in the array.

 In C# the allocation of memory for the arrays is done dynamically.

 The variables in the array are ordered and each has an index beginning from 0.

 C# array is an object of base type System.Array

o Therefore, it is easy to find their size using the predefined functions.

 Default values of numeric array and reference type elements are set to be respectively zero and null.
4
ARRAY … (2)

C# ARRAYS

SINGLE MULTI-
JAGGED
DIMENSIONAL DIMENSIONAL

ARRAYS OF ARRAY
5
ARRAY … SINGLE DIMENSIONAL ARRAY
6
ARRAY … MULTI DIMENSIONAL ARRAY
C# ARRAY OPERATIONS USING SYSTEM.LINQ … (1)
7

In C#, we have the System.Linq namespace that provides different methods to perform various

operations in an array. For example,

 Find Minimum and Maximum Element


int[] numbers = {51, 1, 3, 4, 98};
// get the minimum element
Console.WriteLine("Smallest Element: " + numbers.Min()); //output: 1
// Max() returns the largest number in array
Console.WriteLine("Largest Element: " + numbers.Max()); //output: 98
C# ARRAY OPERATIONS USING SYSTEM.LINQ … (2)
8

 Find the Average of an Array


int[] numbers = {30, 31, 94, 86, 55};
// get the sum of all array elements
float sum = numbers.Sum();
// get the total number of elements present in the array
int count = numbers.Count();
float average = sum/count;
Console.WriteLine("Average : " + average); //output: 59.2
// compute the average
Console.WriteLine("Average using Average() : " + numbers.Average()); //output: 59.2

Note: It is compulsory to use the System.Linq namespace while


using Min(), Max(), Sum(), Count(), and Average() methods.
9
COMMON ARRAY FUNCTIONS … (1)

Function Explanation Example

Gets the total number of elements in all the


Length arrName.Length;
dimensions of the Array.

Sort Sort an array Array.Sort(arrName);

Sets a range of elements in an array to the


Clear Array.Clear(arrName, startindex, length);
default value of each element type.

Returns the number of elements in specified


GetLength arrName.GetLength(index);
dimension

GetValue Returns the value of specified items arrName.GetValue(index);

IndexOf Returns the index position of value Array.IndexOf(arrName, element);

Copy Copy array elements to another elements Array.Copy(arrName1,NewArray, length);

Copies all the elements of the current one-


CopyTo arrName.CopyTo(NewArray, startindex);
dimensional array to the specified 1D array.
10
COMMON ARRAY FUNCTIONS … (2)

Function Explanation Example

BinarySearch() used to search a value in a sorted one dimensional array Array.BinarySearch(arrName, element);

return true if both arrays are referencing the same


Equals() arrName1.Equals(arrName2)
memory address

Determines whether the specified array contains Array.Exists(arrName, e=>e ==


Exists()
elements that match the conditions element);
Array.Find(arrName,
Searches for an element that matches the conditions and
Find() e => e.StartsWith("S“);
returns the first occurrence within the entire Array.

Array.Find(arrName,
FindAll() Retrieves all the elements that match the conditions.
e => e.StartsWith("S“);

Note: Find() and FindAll() differ in return


11
COMMON ARRAY FUNCTIONS … (3)

Function Explanation Example

Reverses the order of the elements in a one-


Reverse() Array.Reverse(arrName);
dimensional Array or in a portion of the Array.

Determines whether every element in the array Array.TrueForAll(myArr, e=>


TrueForAll()
matches the conditions e.StartsWith("S“);

Array arr =
CreateInstance() Initializes a new instance of the Array class.
Array.CreateInstance(typeof(String), 6);

Sets the specified element in the current Array to


SetValue() arrName.SetValue(“Element", index);
the specified value.

Gets the value of the specified element in the


GetValue() arrName.GetValue(index)
current Array.
12
STRING … (1)

 A string is an object of type String whose value is text.

 Internally, the text is stored as a sequential read-only collection of Char objects.

 In C#, a string (== System.String) is an immutable (unchangeable) sequence of characters stored

in a certain address in memory..

 For declaring the strings we will continue using the keyword string, which is an alias in C# of the

System.String class from .NET Framework.

 The work with string facilitates us in manipulating the text content


13
STRING … (2)

string greeting = "HELLO, C#";

 Declared the variable greeting of type string whose content is the text phrase "Hello, C#".

 The representation of the content in the string looks closely to this:

H E L L O , C #

 The internal representation of the class is  However, there are some disadvantages too:

quite simple – an array of characters. o Filling in the array happens character by character, not at once.

 We can avoid the usage of the class by o We should know the length of the text in order to be aware

declaring a variable of type char[] and fill in whether it will fit into the already allocated space for the array.

the array’s elements character by character. o The text processing is manual.


14
STRING … (3)

 Strings are very similar to the char arrays (char[]), but unlike them, they cannot be modified.

 Like the arrays, they have properties such as Length, which returns the length of the string and allows access by

index.

 Indexing, as it is used in arrays, takes indices from 0 to Length-1.

 Access to the character of a certain position in a string is done with the operator [] (indexer), but it is allowed only

to read characters (and not to write to them):

string str = "abcde";

char ch = str[1]; // ch == 'b'

str[1] = 'a'; // Compilation error!

ch = str[50]; // IndexOutOfRangeException
15
STRING … (4)

Strings – Simple Example

string message = "This is a sample string message.";

Console.WriteLine("message = {0}", message);

Console.WriteLine("message.Length = {0}", message.Length);

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

Console.WriteLine("message[{0}] = {1}", i, message[i]);

}
16
STRING … (5)

Strings Escaping

 As we already know, if we want to use quotes into the string content, we must put a slash before them to

identify that we consider the quotes character itself and not using the quotation marks for ending the string:

string quote = "Book's title is \"Intro to C#\"";

// Book's title is "Intro to C#"

 The quotes in the example are part of the text.

 They are added in the variable by placing them after the escaping character backslash (\).

 In this way the compiler recognizes that the quotes are not used to start or end a string, but are a part of the data.

 Displaying special characters in the source code is called escaping.


17
STRING … (6)

 We can initialize string variables in the following three ways:

# Method Example

1 By assigning a string literal. string str1 = “HELLO WORLD”

2 By assigning the value of another string string str2 = str1;

By passing the value of an operation which string email = "[email protected]";


3
string info = "My mail is: " + email;
returns a string.
----------------------------------------------------------- OR
string WelcomeUser(string user)
{
return "Welcome " + user;
}
string str3 = WelcomeUser("Admin");
18
STRING … (7)

 First, we declare and initialize the variable str1.


string str1 = “HELLO WORLD”
 Then the variable str2 takes the value of str1.
string str2 = str1;
 Since the string class is a reference type, the text

"HELLO WORLD" is stored in the dynamic memory

(heap) on an address defined by the first variable.

STR1 HEAP
 str1 && str2 are variable name

HELLO WORLD  #12e2023 Memory block address

 HELLO WORLD is value in the memory block


#12e2023
STR2
19
STRING … (8)

 The string class provides a wide range of methods and properties that you can use to manipulate and work

with strings. Some of the commonly used methods and properties of the string class include:

o Length: returns the length of the string

o IndexOf: finds the index of a specified character or substring in the string

o SubString: returns a substring of the string

o ToLower and ToUpper: convert the string to lowercase or uppercase

o Replace: replaces a specified character or substring with another character or substring

o Trim: removes any leading or trailing whitespace characters from the string

o Split: splits the string into an array of substrings based on a specified delimiter character or substring

o Contains: Returns true if string contains specified value.

o Remove: Removes the character from startIndex.


20
STRING … (9)

o Insert: Insert new string at given index.

o Copy: Create a new string that points to the previous object

o Clone: Creates a new string that points to new object

o Compare: This method returns an int value, if string1 is smaller than string2 then it returns -1, if

string1 is larger than string2 then it returns 1, if both strings are equal then it returns 0.

o Equals: Returns true if both strings are equal.

o IsNullOrEmpty: Returns true if string contains blank or null value.

o IsNullOrWhiteSpace: Returns true if string contains blank, null or any whitespace characters.
21
STRING … (10)

 string text = " Hello, World! ";

• Console.WriteLine("Original Text: {0}", text);

 string trimmedText = text.Trim();

• Console.WriteLine("Trimmed Text: {0}", trimmedText);

 int length = trimmedText.Length;

• Console.WriteLine("Length of Trimmed Text: {0}", length);

 int index = trimmedText.IndexOf("World"); //IndexOf(chracter/Substring)

• Console.WriteLine("index of word in Trimmed Text: {0}", index);

 string subString = trimmedText.Substring(0, 5); // SubString(int startIndex, int length)

• Console.WriteLine("Substring of Trimmed Text: {0}", subString);


22
STRING … (11)

 string upperCaseText = trimmedText.ToUpper(); // Similar for ToLower()

• Console.WriteLine("UPPERCASE of Trimmed Text: {0}", upperCaseText);

 string replacedText = trimmedText.Replace("World", "Africa");

• Console.WriteLine("Africa Instead of world in Trimmed Text: {0}", replacedText);

 string[] words = trimmedText.Split(","); //split the string by comma

• Console.WriteLine("Character Array First Element: {0}",words[0]);

• Console.WriteLine("Character Array Second Element: {0}", words[1]);

 int CompareResult = string.Compare(text, replacedText);

• Console.WriteLine("Compare Result: {0}", CompareResult);

 string textCopy = string.Copy(trimmedText); // Points to the same object reference

• Console.WriteLine("Copy String: {0}", textCopy);


23
STRING … (12)

 bool areEqual = string.Equals("Apple", "apple");

• Console.WriteLine("Are Equal?: {0}", areEqual);

• Console.WriteLine("Is text NULL ? : {0}", string.IsNullOrEmpty(trimmedText));

 string cloneText = (string)trimmedText.Clone(); //Points to the new object reference

• Console.WriteLine("Clone Text: {0}", cloneText);

 bool containText = trimmedText.Contains("W");

• Console.WriteLine("Is text contains W?: {0}", containText);

 string removedText = trimmedText.Remove(5); //Remove(int startIndex)

• Console.WriteLine("New string after Removing: {0}", removedText);

 string insertedText = trimmedText.Insert(12, "..."); //Insert(int startIndex, string newString)

• Console.WriteLine("After Inserting ... : {0}", insertedText);


24
STRING … (13)

COPY
CLONE

string str1 = “HELLO WORLD”


string str2 = str1; string str2 = (string) str1.Clone();

-----------------------------------------------------
string str2 = string.Copy(str1);
STR1 HEAP

HELLO WORLD
STR1 HEAP
#12e2023

HELLO WORLD STR2


HELLO WORLD
#13d3023
#12e2023
STR2
25
STRING … (13)

COPY
CLONE

AFTER COPY: Tuesday AFTER CLONE: Feb

AFTER COPY: Tuesday AFTER CLONE: Yekatit


26
STRUCTURE … (1)

 A structure in C# is simply a composite data type consisting

of a number elements of other types.

 A structure is a data type in C# that combines different data

variables into a single unit.

 The keyword struct is used to create the structures.

The syntax of a structure definition is given as follows:


struct NameOfStructure
{
// Member variables
}
27
STRUCTURE … (2)

 Structures are used to represent a record.

 Suppose you want to keep track of your books in a library.

 You might want to track the following attributes about each book

struct Books
{
public string title;
public string subject;
};
28
STRUCTURE … (3)

using System; 1 public class testStructure { 2


struct Books public static void Main(string[] args) {
{ Books Book1; /* Declare Book1 of type Books */
public string title; Books Book2; /* Declare Book2 of type Books */
public string subject; /* book 1 specification */
}; Book1.title = "C Programming";
Book1.subject = "C Programming Tutorial";
/* book 2 specification */
Book2.title = "Telecom Billing";
Book2.subject = "Telecom Billing Tutorial";
29
STRUCTURE … (4)

/* print Book1 info */ 3


Console.WriteLine( "Book 1 title : {0}", Book1.title);
Console.WriteLine("Book 1 subject : {0}", Book1.subject);
/* print Book2 info */
Console.WriteLine("Book 2 title : {0}", Book2.title);
Console.WriteLine("Book 2 subject : {0}", Book2.subject);
}
}
30
CLASS WORK

Write a program that allow to register students with the following information

{ name, department, studId, and gender}. Finally, display registered students in

tabular form. [Using Structure Concept]

EXPECTED OUTPUT
# Name StudID Gender Department

1 Abebe CEP001 M SENG

2 Ujulu CEP002 M SENG

3 Selam CEP003 F SENG


31
LIST … (1)

 The first thing to understand is that the C# List is a

simple ordered list of items that has the ability to store

any type of object, just like an array.

 It is a generic data structure that can hold any type.

 Use the new operator and declare the element type in

the angle brackets < > (List<T>).

 This means that if you want a List of integers of the int

data type then you can create a List that will store only

the int type.


32
LIST … (1)

 To work with the C# List, you need to add the following namespace at the beginning

your code:

o using System.Collections.Generic;

 List<T> listName; // declaration

 listName = new List<T>(); // creation

 List<T> listName = new List<T>(); // declaration & creation

Note: Separately declare and create when required is efficient in


use than declaring and creating once
33
LIST … (2)

 Unlike a C# array, a C# list does not have a limited number of elements.

 You can add as many items as you like.

// Initialize array with length 2 // Initialize list; no length needed

string[] citiesArray = new string[2]; List<string> citiesList = new List<string>();

citiesArray[0] = “Addis Ababa"; citiesList.Add(“Addis Ababa");

citiesArray[1] = “Adama"; citiesList.Add(“Adama");

citiesArray[2] = “Jimma"; // Error! citiesList.Add(“Jimma");


34
LIST … (3)

 C# List class provides several methods for manipulating the items it contains.
35
LIST … (4)

 The number of elements in a list is stored  Capacity property used to limit number of elements in a list.

in the Count property.  In the example code, the Capacity of citiesList is 4 by default

 In the example code, the Count of


List<string> citiesList = new List<string>();
citiesList changes as we add values.
citiesList.Add(“Addis Ababa");
Console.WriteLine(citiesList.Capacity);
List<string> citiesList = new List<string>(); // Output: 4
citiesList.Add(“Addis Ababa"); citiesList.Add(“Jimma");
Console.WriteLine(citiesList.Count); citiesList.Add(“Adama");
// Output: 1 citiesList.Add(“Harar");
citiesList.Add(“Adama"); citiesList.Add(“Haramaya");
Console.WriteLine(citiesList.Count); Console.WriteLine(citiesList.Capacity);
// Output: 2 // Output: 8

Count() Capacity()
36
LIST … (5)

Remove()
List<string> citiesList = new List<string>();
citiesList.Add(“Addis Ababa");
 Elements of a list can be removed
citiesList.Add(“Adama");
with the Remove() method. The
citiesList.Add(“Jimma");
method returns true if the item is bool res = citiesList.Remove(“Addis Ababa"); //True
successfully removed; otherwise, bool res = citiesList.Remove(“Mekele"); //False

false. foreach (string city in citiesList) {


Console.WriteLine(city);
 In the example code, attempting to
}
remove “Mekele" returns false
//Output :
because that element is not in the Adama
citiesList. Jimma
37
LIST … (6)

Clear()

 All elements of a list can be removed


List<string> citiesList = new List<string> {
with the Clear() method. It returns
“Hawasa", “Dire Dawa", “Gondar" };
nothing. citiesList.Clear();

 In the example code, the list is


Console.WriteLine(citiesList.Count);
initialized with three items. After calling
// Output: 0
Clear(), there are zero items in the list.
38
LIST … (7)

Contains()

 In C#, the list method Contains()


List<string> citiesList = new List<string> { “Hawasa",
returns true if its argument exists in “Dire Dawa", “Gondar" };

the list; otherwise, false.


bool result1 = citiesList.Contains(“Hawasa");
 In the example code, the first call
// result1 is true
to Contains() returns true because
bool result2 = citiesList.Contains(“Asosa");
“New York City” is in the list. The
// result2 is false
second call returns false because

“Cairo” is not in the list.


39
LIST … (8)

Range-related Methods
string[] african = new string[] { "Cairo", "Johannesburg" };
string[] asian = new string[] { "Delhi", "Seoul" };
 Unlike elements in a C# array, multiple
List<string> citiesList = new List<string>();
elements of a C# list can be accessed,
// Add two cities to the list
added, or removed simultaneously.
citiesList.AddRange(african);
 A group of multiple, sequential
// List: "Cairo", "Johannesburg"
elements within a list is called a range.
// Add two cities at index=0
 Some common range-related methods
citiesList.InsertRange(0, asian);
are: AddRange(); InsertRange(); // List: "Delhi", "Seoul", "Cairo", "Johannesburg"
// Remove 2 elements starts from index=1
RemoveRange()
citiesList.RemoveRange(1, 2);

// List: "Delhi", "Johannesburg"


40
LIST … (9)

struct Customer
{
public string Name;
public string City;

public Customer(string name, string city) : this()


{
Name = name;
List<Customer> customers = new List<Customer>();
City = city;
} customers.Add(new Customer("Amir", "Aweday"));
}
customers.Add(new Customer(“Semira", “Aweday"));
customers.Add(new Customer("Ujulu", “Addis Ababa"));
customers.Add(new Customer(“Obang", “Addis Ababa“));
customers.Add(new Customer(“Feysal", “Harar“));
customers.Add(new Customer("Selam", "Harar" ));
41
LIST … LINQ (1)

 LINQ is a set of language and framework features for writing queries on collection types.

 It is useful for selecting, accessing, and transforming data in a dataset.

 LINQ features can be used in a C# program by importing the System.Linq namespace.

VAR
var findCustomer = from cust in
Since the type of an executed LINQ query’s
customers where cust.City == “Aweday"
result is not always known, it is common to
select cust;
store the result in an implicitly typed variable
//Output
using the keyword var. Amir, Aweday
Semira, Aweday
42
LIST … LINQ (2)

// Method syntax
var findCustomer = customers.Where(cust => cust.City ==
METHOD & QUERY SYNTAX
“Aweday");
 In C#, LINQ queries can be written

in method syntax or query syntax. // Query syntax

 Method syntax resembles most var findCustomer = from cust in customers where cust.City
== “Aweday" select cust;
other C# method calls, while query

syntax resembles SQL.


//Output
Amir, Aweday
Semira, Aweday
43
LIST … LINQ (2)

WHERE

In LINQ queries, the Where operator is


// Query syntax
used to select certain elements from a var findCustomer = from cust in customers where cust.City ==
“Harar" select cust;
sequence.
// Method syntax
 It expects an expression that evaluates
var findCustomer = customers.Where(cust => cust.City ==
to a Boolean value. “Harar");
foreach (var custm in findCustomer)
 Every element satisfying the condition {
Console.WriteLine(custm.Name);
will be included in the resulting query. }
// Result: Feysal, Selam
 It can be used in both method syntax

and query syntax.

Note: Customer is structure with Name and City Attributes


44
LIST … LINQ (3)

FROM
string[] names = { “Amir", “Ujulu", “Selam", “Chala" };
 In LINQ queries, the from operator
var query = from n in names where n.Contains("a")
declares a range variable that is used
select n;
to traverse the sequence. It is only used

in query syntax. foreach (var name in query)


{
 In the example code, n represents each Console.WriteLine(name);
element in names. The returned query }

only contains those elements for which


// Result: Selam, Chala
n.Contains("a") is true.
45
LIST … LINQ (4)

string[] names = { “Amir", “Ujulu", “Selam", “Chala" };


SELECT // Query syntax

 In LINQ queries, the Select var cap = from n in names select n.ToUpper();
// Method syntax
operator determines what is
var cap = names.Select(t => t.ToUpper());
returned for each element in the
foreach (var name in cap)
resulting query. It can be used in
{
Console.WriteLine(name);
both method and query syntax.
}
// Result: AMIR, UJULU, SELAM, CHALA
46
CLASS WORK

Write a program that allow to register students with the following information

{ name, department, studId, and gender}. Finally, display registered students in

tabular form. [Using List Concept]

EXPECTED OUTPUT
# Name StudID Gender Department

1 Abebe CEP001 M SENG

2 Ujulu CEP002 M CS

3 Selam CEP003 F SENG

FEATURE: Allow the user to search by Gender and Department Using LINQ
47
DICTIONARY … (1)

 In C#, Dictionary is a generic collection which is generally used to

store key/value pairs.

 The keys must be unique, but the values can be duplicated.

 Dictionaries are implemented as hash tables so their keys can

quickly access them.

 Here are some of the advantages of using dictionaries in C#:

o They are very efficient for accessing values by their keys.

o They can be used to store a large number of key-value pairs.

o They are easy to use and manage.


48
DICTIONARY … (2)

 Here are some examples of when you might use a dictionary in C#:

 To store a mapping of:

 Names to phone numbers.

 Countries to capital cities.

 Words to their definitions.

 User-IDs to user profiles.

 Product-IDs to product prices.


49
DICTIONARY … (3)

 using System.Collections.Generic;
// Create a dictionary SYNTAX
Dictionary<TKey, TValue> DictName = new Dictionary<TKey, TValue> ();
// Where TKey is the type of the keys, and TValue is the type of the values.

Dictionary<int, string> PhoneContacts = new Dictionary<int, string>();

Dictionary< string, string> CapitalCities = new Dictionary< string, string>();

Dictionary< string, string> WordDefinitions = new Dictionary< string, string>();

Dictionary< string, string> UserIDs = new Dictionary< string, string>();


50
DICTIONARY … BASIC OPERATIONS (1)

ADD ELEMENTS Dictionary<int, string> Contacts = new Dictionary<int, string>();


 C# provides the Add()
Contacts.Add(920, "Abebe");
method using which we can
Contacts.Add(910, "Amir");
add elements in the Contacts.Add(909, "Ujulu");
dictionary.
51
DICTIONARY … BASIC OPERATIONS (1)

ACCESS ELEMENTS // create a dictionary 1


 We can access the elements Dictionary<int, string> Contacts = new Dictionary<int, string>();

inside the dictionary using // add items to dictionary

it's keys. Contacts.Add(920, "Abebe");


Contacts.Add(910, "Amir");
 In C#, we can also loop
Contacts.Add(909, "Ujulu");
through each element of the
// access the value having key = 0910
dictionary using a foreach
Console.WriteLine(Contacts[910]);
loop.
52
DICTIONARY … BASIC OPERATIONS (1)

// create a dictionary
2
Dictionary<int, string> Contacts = new Dictionary<int, string>();
ACCESS ELEMENTS
// add items to dictionary
 We can access the elements
Contacts.Add(920, "Abebe");
inside the dictionary using it's Contacts.Add(910, "Amir");
keys. Contacts.Add(909, "Ujulu");
// iterate through the car dictionary
 In C#, we can also loop through
foreach (KeyValuePair<int, string> contact in Contacts)
each element of the dictionary
{
using a foreach loop. Console.WriteLine(“Key: {0}, Value: {1}", contact.Key, contact.Value);
}
53
DICTIONARY … BASIC OPERATIONS (1)

Dictionary<int, string> Contacts = new Dictionary<int, string>();


Contacts.Add(920, "Abebe");
Contacts.Add(910, "Amir");
REMOVE ELEMENTS
Contacts.Add(909, "Ujulu");
 To remove the elements inside
foreach(KeyValuePair<int, string> contact in Contacts)
the dictionary we use: Remove() {
Console.WriteLine(“Key: {0}, Value: {1}", contact.Key, contact.Value);
- removes the key/value pair }
Contacts.Remove(909); // remove Ujulu from the Dictionary
from the dictionary
Console.WriteLine("\nModified Dictionary :");
foreach (KeyValuePair<int, string> contact in Contacts)
{
Console.WriteLine(“Key: {0}, Value: {1}", contact.Key, contact.Value);
}
54
HOMEWORK

Discuss about the difference between Structure and Class

DEVELOP COLLEGE REGISTRAR CONSOLE APPLICATION THAT ENABLES


 To register students with {Name, Id, Gender, Department, Phone}
withssssdd
 To display inserted data in tabular form
 To change student information
 To Remove mistakenly registered students
 Count and display number of Male and Female
 Select only female students and display their ID and Name

NOTE:
 APPLY STRUCTURE, LIST & DICTIONARY DATA STRUCTURES AND CONSIDER HCI CONCEPTS
TEACHING YOU IS GOOD LUCK

You might also like