0% found this document useful (0 votes)
2K views15 pages

C# Practical File

This document outlines 10 programming practices in C#. Each practical demonstrates a different concept: 1) namespaces and comments, 2) printing an array with foreach, 3) inheritance, 4) constructors, 5) interfaces, 6) inheriting an interface, 7) operator overloading, 8) exception handling, 9) ilist interfaces, and 10) dictionaries and iDictionary interfaces. For each practical there is sample code provided and expected output. The document also includes an index listing the practical name and page number. Preface, certificate, and acknowledgement sections are included.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
2K views15 pages

C# Practical File

This document outlines 10 programming practices in C#. Each practical demonstrates a different concept: 1) namespaces and comments, 2) printing an array with foreach, 3) inheritance, 4) constructors, 5) interfaces, 6) inheriting an interface, 7) operator overloading, 8) exception handling, 9) ilist interfaces, and 10) dictionaries and iDictionary interfaces. For each practical there is sample code provided and expected output. The document also includes an index listing the practical name and page number. Preface, certificate, and acknowledgement sections are included.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 15

Practical 1:

A program using namespaces and comments -

Output: Hello
Practical 2:

A program to print array value using foreach statement -

Output: 11 22 33 44
Practical 3:

A program to illustrate a simple inheritance –

Output:
Practical 4:

A program to show the application of Constructors -

Output: Area1 = 150


Practical 5:

A program to show the implementation of multiple interface –

Output:
Sum = 30
Product = 200
Practical 6:

A program to inherit a class that implements an interface –

Output:
Derived Display
Base Display
Practical 7:

A program to show operator + overloading –

Output:
Practical 8:

A program to use try and catch for exception handling –

Output:
Division by zero
y=1
Practical 9:

A program to demonstrate ilist interfaces -

using System;
using System.Collections.Generic;

class Program
{
static void Main()
{
int[] a = new int[3];
a[0] = 1;
a[1] = 2;
a[2] = 3;
Display(a);

List<int> list = new List<int>();


list.Add(5);
list.Add(7);
list.Add(9);
Display(list);
Console.ReadLine();
}

static void Display(IList<int> list)


{
Console.WriteLine("Count: {0}", list.Count);
foreach (int num in list)
{
Console.WriteLine(num);
}
}
}

Output:
Count: 3
123
Count: 3
579
Practical 10:

1. A program to demonstrate Dictionary interface –

using System;
using System.Collections.Generic;  
  
class Demo {
  
        // Main Method 
    static public void Main () {
          
        // Creating a dictionary
        // using Dictionary<TKey,TValue> class
        Dictionary<int, string> My_dict1 =  
                       new Dictionary<int, string>(); 
            
          // Adding key/value pairs 
          // in the Dictionary
          // Using Add() method
          My_dict1.Add(1123, "Welcome");
          My_dict1.Add(1124, "to");
          My_dict1.Add(1125, "Demo");
            
          Foreach (KeyValuePair<int, string> ele1 in My_dict1)
          {
              Console.WriteLine("{0} and {1}",
                        ele1.Key, ele1.Value);
          }
          Console.WriteLine();
            
          // Creating another dictionary
          // using Dictionary<TKey,TValue> class
      // adding key/value pairs without
          // using Add method
      Dictionary<string, string> My_dict2 =  
              new Dictionary<string, string>(){
                                  {"a.1", "Dog"},
                                  {"a.2", "Cat"},
                                {"a.3", "Pig"} }; 
           
          Foreach (KeyValuePair<string, string> ele2 in My_dict2)
          {
              Console.WriteLine("{0} and {1}", ele2.Key, ele2.Value);
          }
    }
}

Output:
1123 and Welcome
1124 and to
1125 and Demo
a.1 and Dog
a.2 and Cat
a.3 and Pig

2. A program to demonstrate iDictionary interface -

using System;
using System.Collections.Generic;

class Program
{
static void Main()
{
Dictionary<string, string> dict = new Dictionary<string, string>();
dict["Tom"] = "Bob";
WriteKeyA(dict);
SortedDictionary<string, string> sort = new SortedDictionary<string, string>();
sort["Tom"] = "Jerry";
WriteKeyA(sort);
Console.ReadLine();
}

static void WriteKeyA(IDictionary<string, string> i)


{

Console.WriteLine(i["Tom"]);
}
}

Output:

Bob
Jerry
Index
S. No. ‘Name of the practical Page NO. Remarks

01 Write a program using namespaces and comments. 1

02 Write a program to print array value using foreach


statement. 2

03 Write a program to illustrate a simple inheritance. 3

04 Write a program to show the application of

Constructors. 4

05 Write a program to show the implementation of

multiple interface. 5

06 Write a program to inherit a class that implements an


interface. 6

07 Write a program to show operator + overloading. 7

08 Write a program to use try and catch for exception


handling. 8

09 Write a program to demonstrate ilist interfaces. 9

10 Write a program to demonstrate. 10-11


PREFACE

This practical file has been prepared in partial


fulfilment of the requirement for the Subject: C#
of the programme B.C.A. (Sem. V) in the academic
year 2019-2020.
Completing the project helped me to deepen and widen
practical knowledge in C#.
All constructive criticism and feedback is cordially
invited.
CERTIFICATE

This is to certify that Anshuman Srivastava has made


this C# Practical file under the supervision and
guidance of my subject teacher “Mrs. Rashmi Kuksal”
for the Academic Session 2019-2020 for partial
fulfillment of Hemvati Nandan Bahuguna Garhwal
University.

(Teacher’s sign)

ACKNOWLEDGEMENT
I would like to express my special thanks of gratitude to
my respected Principal and my subject teacher “Mrs.
Rashmi Kuksal” for their guidance and support in
completing the practical file.
Secondly, I would also like to thank my parents and
friends who helped me a lot in finalizing this project
within the limited time frame.

You might also like