0% found this document useful (0 votes)
9 views2 pages

Exercices On C#

The document outlines a series of exercises designed to teach the C# programming language, covering topics such as basics, control flow, arrays, functions, object-oriented programming, exception handling, LINQ, file handling, delegates, events, and advanced topics. Each section includes specific programming tasks aimed at reinforcing the concepts. Additionally, there are extra challenges to simulate real-world applications like a library management system and a CRUD application.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Exercices On C#

The document outlines a series of exercises designed to teach the C# programming language, covering topics such as basics, control flow, arrays, functions, object-oriented programming, exception handling, LINQ, file handling, delegates, events, and advanced topics. Each section includes specific programming tasks aimed at reinforcing the concepts. Additionally, there are extra challenges to simulate real-world applications like a library management system and a CRUD application.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

EXERCICES ON C# PROGRAMMING LANGUAGE

Exercises on C# Programming

1. Basics of C# Programming

 Write a C# program to print "Welcome to C# Programming!" to the console.


 Create a program that declares variables of different data types (e.g., int, float,
bool, string) and demonstrates operations on them (e.g., arithmetic, concatenation).
 Write a program to calculate the area of a circle based on user input for the radius. Use
the formula: Area = π * radius * radius (use Math.PI).

2. Control Flow

 Write a program that checks whether a number entered by the user is odd or even
using an if-else statement.
 Create a simple program that accepts a grade (A, B, C, D, or F) from the user and
outputs a message based on the grade using a switch statement.
 Use a for loop to print the Fibonacci sequence up to a given number.
 Write a program using a while loop that calculates the sum of digits of a number
entered by the user.

3. Arrays and Collections

 Create a program to find the largest and smallest numbers in a one-dimensional array.
 Write a program to initialize a two-dimensional array and display its elements in a
matrix format.
 Use a List<int> to store and display user-entered numbers, and calculate their
average using LINQ.

4. Functions

 Write a program to create a method IsPrime() that checks if a given number is prime,
and use this method to print all prime numbers in a range.
 Implement a method ReverseString() that takes a string as input and returns the
reversed string.
 Create an overloaded version of a method Calculate() that computes the square of
an integer and the cube of a floating-point number.

5. Object-Oriented Programming

 Write a C# class called Person with properties Name and Age, and a method
DisplayInfo() that prints the details. Create objects of the class and use them.
 Create a program that demonstrates inheritance. Define a base class Vehicle with a
method DisplayDetails(). Derive a Car class and override the method.
 Implement a simple banking system using classes with functionalities like deposit,
withdrawal, and balance check.

6. Exception Handling
 Write a program to handle DivideByZeroException using try-catch.
 Create a program that throws a custom exception when the user inputs an invalid age
(e.g., negative numbers).
 Implement a program to demonstrate a finally block, ensuring cleanup of resources
(like file handling).

7. LINQ

 Write a program using LINQ to filter and display even numbers from a list of integers.
 Create a program to find the maximum, minimum, and average values in an array
using LINQ.
 Use LINQ to query a list of strings and display only those that start with a given letter.

8. File Handling

 Write a program to create a text file, write a series of numbers into it, and then read
the numbers and display them.
 Create a program to count the number of words and lines in a text file.
 Write a program to append user-entered text to an existing file.

9. Delegates and Events

 Write a program to demonstrate a delegate that points to methods for addition and
subtraction.
 Create a simple event handling example where an event is raised when a specific
condition is met (e.g., temperature exceeds a threshold).

10. Advanced Topics

 Implement a program that demonstrates the use of async and await for reading and
writing to files.
 Create a program using generics that defines a GenericList<T> class to store and
manage items of any type.
 Write a program to demonstrate the use of a Task to execute a piece of code in a
separate thread.

Additional Challenges

1. Write a program to simulate a library management system where books can be added,
borrowed, or returned using classes and collections.
2. Implement a CRUD (Create, Read, Update, Delete) application using a console-based
interface and file handling for storing data persistently.
3. Create a program that uses LINQ to group and sort data from a list of objects (e.g.,
employees grouped by department and sorted by salary).

You might also like