CSharp training

Nishchit
5 min readSep 27, 2022

--

C# (C-Sharp) is a programming language developed by Microsoft that runs on the .NET Framework.

C# is used to develop web apps, desktop apps, mobile apps, games and much more.

The c sharp concept started on 23 september 2022. The session started with learning the basic concepts of csharp. First we installed the visual studio 2022. The csharp can be worked in the visual studio installer environment only. So we installed it.

Then we started to do the basics of the csharp . We learnt how to do the initialization and the basics of coding in csharp.

Then the topics one by one started and then the the basics covered clearly . then it was done one by doen and the atsk was assigned as the progress followed.

Task12:

  1. Practice all the below concepts:
    ->instance and static methods
    ->Control statements
    ->enumeration
    2. WAP to accept all the employee details using static method and display the details in an instance method:

Task13:

  1. Show the working of Matrix Addition using 2-D Arrays.
    2. Perform a multiplication table operation using params array.
    3. Get the student details(sid,sname,sdep) using out keyword.

Then we started to learn about access specifiers in CSharp. It made clear for us how to use it and how it is used in the program given any situation.

This helped us to the understand advanced level for some extent and made easy to work with the task then we had lot of work in task to be done before completing the session. Then we started to work on the concepts of Access specifiers.

Acess specifiers in c#:

1)Public
It specifies that access is not restricted.

2)Protected
It specifies that access is limited to the containing class or in derived class.

3)Internal
It specifies that access is limited to the current assembly.

4)Private
It specifies that access is limited to the containing type.

We also went on to study oops concept and there we learnt to use the encapsulation, abstraction, Inheritance concept in the c# programming.

Task14:

  1. Show the difference between public and internal programmatically.
    2. Show the working of Constructor Overloading:
    add(int,int),add(float,float),add(string,string)
    3. Show the working of inheritance and protected access specifier.
    Classes: Parent-> Bonus, Child -> Staff → 3 times the bonus, NonStaff -> 2 times the bonus
    4. Using Regular expression validate a 10 digit mobile number.
    Note: First digit must be(9or8or7)

Call by Value:
In C#, value-type parameters are that pass a copy of original value to the function rather than reference. It does not modify the original value. A change made in passed value does not alter the actual value.

Call by reference:
C# provides a ref keyword to pass argument as reference-type. It passes reference of arguments to the function rather than copy of original value. The changes in passed values are permanent and modify the original variable value.

Out parameter:
C# provides out keyword to pass arguments as out-type. It is like reference-type, except that it does not require variable to initialize before passing. We must use out keyword to pass argument as out-type. It is useful when we want a function to return multiple values.

Constructor:
Constructor is a special method which is invoked automatically at the time of object creation. It is used to initialize the data members of new object generally. The constructor in C# has the same name as class or struct.

Destructor:
A destructor works opposite to constructor, It destructs the objects of classes. It can be defined only once in a class. Like constructors, it is invoked automatically.

Task15:

1. Write a program to show the working of multiple catch blocks and display the various properties of an exception.
2. Write a program to create a user-defined to validate the age>22.

Filestream:
Filestream class provides a stream for file operation. It can be used to perform synchronous and asynchronous read and write operations. By the help of Filestream class, we can easily read and write data into file.

Stream Writer:
StreamWriter class is used to write characters to a stream in specific encoding. It inherits TextWriter class. It provides overloaded write() and writeln() methods to write data into file.

StreamReader:
StreamReader class is used to read string from the stream. It inherits TextReader class. It provides Read() and ReadLine() methods to read data from the stream.

TextWriter:
TextWriter class is an abstract class. It is used to write text or sequential series of characters into file. It is found in System.IO namespace.

TextReader:
TextReader class is found in System.IO namespace. It represents a reader that can be used to read text or sequential series of characters.

Serialization:
Serialization is the process of converting object into byte stream so that it can be saved to memory, file or database.

Deserialization:
deserialization is the reverse process of serialization. It means you can read the object from byte stream. Here, we are going to use BinaryFormatter.Deserialize(stream) method to deserialize the stream.

Delegates:
A delegate is a type that represents references to methods with a particular parameter list and return type. When you instantiate a delegate, you can associate its instance with any method with a compatible signature and return type. You can invoke (or call) the method through the delegate instance.

Task16:

Show the working of Multicast delegates to calculate the interest rate for the following categories:
PARAMETERS →BANKNAME,INTEREST RATE

SBI
2.70%
HDFC Bank
3.00% — 3.50%
Kotak Mahindra Bank
3.50%
Axis Bank
3.00% — 3.50%
ICICI Bank
3.00% — 3.50%

--

--