1 of 35

What is C#.NET?

The C#.NET is one of the Microsoft programming languages. It is the most powerful programming language among all programming languages available in the .NET Framework. The C#.NET contains all the features of C++, VB.NET, JAVA, and also some additional features.

The C#.Net programming language is designed to be a simple, modern, general-purpose, and completely object-oriented programming language.

2 of 35

In this you will learn from basic to advance level concepts of C#. Some of them are as follows:

Architecture of the .NET FrameworkBasic Concepts of C#

3 of 35

Introduction to DOT NET Framework

In this article, I am going to give you an overview of the DOT NET Framework. This is important for you as a dot net developer to know the history and evolution of the DOT NET Framework. Here, in this article, we will discuss what was there before the DotNet Framework and what problems we face in that, and how we overcome all those problems in the DOT NET Framework. Before DOT NET Framework COM  is there. So, let us first discuss what is COM and what problems we face in COM.

What is COM?

COM stands for Component Object Model. The COM is one of Microsoft Technologies. Using this technology we can develop windows applications as well as web applications. In earlier COM, VB is the programming language that is used to implement windows applications and ASP is used to implement web applications.

What are the disadvantages of COM?

The major two disadvantages of COM is

  1. Incomplete object-oriented programming means it will not support all the features of OOPs.
  2. Platform dependent means COM applications can run on only Windows OS.

To overcome the above problems, the DOT NET Framework comes into the picture.

What .NET Represents?

NET stands for Network Enabled Technology. In .NET, dot (.) refers to object-oriented and NET refers to the internet. So the complete .NET means through object-oriented we can implement internet-based applications.

What is a Framework?

A framework is a software. Or you can say a framework is a collection of many small technologies integrated together to develop applications that can be executed anywhere.

4 of 35

What does the DOTNET Framework provide?

The DOTNET Framework provides two things are as follows

  1. BCL (Base Class Libraries)
  2. CLR (Common Language Runtime)

BCL

Base Class Libraries (BCL) is designed by Microsoft. Without BCL we can’t write any code in .NET. So, BCL is also known as the Building block of .NET Programs. These are installed into the machine when we installed the .NET framework. BCL contains pre-defined classes and these classes are used for the purpose of application development.

The physical location of BCL is C:\Windows\assembly

CLR

CLR stands for Common Language Runtime and it is the core component under the .NET framework which is responsible for converting the MSIL (Microsoft Intermediate Language) code into native code. In our next article, we will discuss CLR in detail.

5 of 35

In the .NET framework, the code is compiled twice.

  1. In the 1st compilation, the source code is compiled by the respective language compiler and generates the intermediate code which is known as MSIL (Microsoft Intermediate Language) or IL (Intermediate language code) Or Managed Code.
  2. In the 2nd compilation, MSIL is converted into Native code (native code means code specific to the Operating system so that the code is executed by the Operating System ) and this is done by CLR.

Always 1st compilation is slow and 2nd compilation is fast.

What is JIT?

JIT stands for the Just-in-Time compiler. It is the component of CLR that is responsible for converting MSIL code into Native Code. Native code is the code that is directly understandable by the operating system.

Different types of DOTNET Framework.

The .net framework is available in three different flavors

  1. DOTNET Framework: This is the general version required to run .NET applications on Windows OS only.
  2. .NET mono Framework: This is required if we want to run DOT NET applications on other OS like Unix, Linux, MAC OS, etc.
  3. DOT NET Compact Framework: This is required to run .NET applications on other devices like mobile phones and smartphones.

There is another company known as “NOVEL” designed a separate framework known as “MONO Framework”. Using this framework we can run MSIL on different OS Like Linux, UNIX, Mac, BSD, OSX, etc.

.NET is platform-dependent using the .NET framework but independent using the MONO framework.

6 of 35

What is not DOT NET?

  1. .NET is not an Operating system.
  2. It is not an application or package.
  3. .NET is not a database
  4. It is not an ERP application.
  5. .NET is not a Testing Tool.
  6. It is not a programming language.

What is exactly DOTNET?

.NET is a framework tool that supports many programming languages and many technologies. .NET support 60+ programming languages. In 60+ programming languages, 9 are designed by Microsoft and the remaining are designed by non-Microsoft.

Microsoft designed programming languages are as follows

  1. VB.NET
  2. C#.NET
  3. VC++.NET
  4. J#.NET
  5. F#.NET
  6. Jscript.NET
  7. Windows Power Shell
  8. Iron phyton
  9. Iron Ruby

7 of 35

Technologies supported by the .NET framework are as follows

  1. ASP.NET (Active Server Pages.NET)
  2. ADO.NET (Active Data Object.NET)
  3. WCF (Windows Communication Foundation)
  4. WPF (Windows Presentation Foundation)
  5. WWF (Windows Workflow Foundation)
  6. AJAX (Asynchronous JavaScript and XML)
  7. LINQ (Language Integrated Query)

What is a language and its need?

  1. Language acts as the mediator between the programmer and the system.
  2. It offers some rules and regulations for writing the program.
  3. The language also offers some libraries which are required for writing the program.

What are Technology and its needs?

  1. Technology is always designed for a particular purpose.
  2. For example development of web-related applications in .NET using a technology ASP.NET.
  3. But the technology does not offer any specific rules for writing the programs. That’s why technology can’t be implemented individually.
  4. VB.NET, C#.NET both are programming languages. Using these two languages we can implement windows/desktop applications individually.
  5. Every language is having its own compiler

8 of 35

Basic Structure of C# Program

In this article, I am going to discuss the Basic Structure of the C# Program using a Console Application. Please read our previous article before proceeding to this article where we discussed the Introduction & Environment Setup for C# Application development. As part of this article, I am going to discuss the following pointers in detail.

  1. What is C#.NET?
  2. Advantages of using the .NET Framework from the C# point of view.
  3. Different Types of applications are developed using C#.NET.
  4. What is the visual studio?
  5. What is a console application?
  6. How to Create a console application using the visual studio?
  7. Understanding the Basic Structure of a C# Program.      Importing section      Namespace Declaration      Class Declaration      Main() method

So, here, first, we will understand what is C#.NET and Visual Studio and what type of applications we can develop using C#.Net. Then we will discuss the basic structure of a C# program using a console application.

9 of 35

What is C#.NET?

  1. C#.NET is one of the Microsoft Programming Languages to work with the .NET Framework to develop different kinds of applications such as Web, Console, Windows, etc. 
  2. It is the most powerful programming language among all programming languages available in the .NET framework because it contains all the features of C++, VB.NET, JAVA, and also some additional features. As we progress in this course, you will come to know the additional features.
  3. C#.NET is a completely Object-Oriented Programming Language. It means it supports all 4 OOPs Principles such as Abstraction, Encapsulation, Inheritance, and Polymorphism.

Based on the features, we can define C# as a simple, secure, robust, portable, platform-independent, architectural neutral, multithreaded, object-oriented programming language with a strong type exception handling and type checking mechanism for developing different kinds of applications such as Web, Windows Form, Console, Web Services, Mobile Apps, etc.

Advantages of using the .NET framework from the C# point of view.

  1. It provides GUI features. Earlier programming languages like C and C++ do not support GUI features but C#.NET will provide complete GUI features. All GUI features are getting from the framework.
  2. We can connect with any database and perform the operations. Using ADO.NET and Entity Framework technologies, we can perform the DB operations with any Database. ADO.NET and Entity Framework are also a part of the .NET Framework.
  3. The Framework also helps us to develop WEB Based applications. Using ASP.NET technology we can develop WEB Based Applications. ASP.NET itself alone cannot develop Web Applications; it requires language support. So, here we can use C# as the programming language. ASP.NET is also a part of the framework.

10 of 35

Different Types of Applications are Developed using C#.NET.

  1. Windows Applications
  2. Web Applications
  3. Restful Web Services
  4. SOAP Based Services
  5. Console Applications
  6. Class Library

What is the Visual Studio?

Visual Studio is one of the Microsoft IDE tools. Using this tool, we can develop, build, compile and run applications with the .NET framework. This tool provides some features such as

  1. Editor
  2. Compiler
  3. Interpreters, and many more

What is a Console Application?

  1. A console application is an application that can be run in the command prompt. For any beginner on .NET or anyone who wants to learn C# Language or anyone who wants to become an expert in C# Language, building a console application is ideally the first step to learning the C# Language.
  2. The Console Applications contain a similar user interface to the Operating systems like MS-DOS, UNIX, etc.
  3. The Console Application is known as the CUI application because in this application we completely work with the CUI environment.
  4. These applications are similar to C or C++ applications.
  5. Console applications do not provide any GUI facilities like the Mouse Pointer, Colors, Buttons, Menu Bars, etc.

11 of 35

Basic Structure of the C# Program

Now, let’s understand the Basic Structure of the C# Program using a Console Application.

The above process is shown in the below diagram.

Note: C#.NET is a Case-Sensitive Language and Every Statement in C# should end with a Semicolon.

12 of 35

Example to Understand the Basic Structure of a C# Program:

Now, we are going to use Visual Studio to create a Console-Type Project. Then we are going to use the console application to display the message “Welcome to C#.NET”. Then, we will also see how to build and run the Console Application using Visual Studio GUI.

Step1

First, open Visual Studio 2022 (the latest version at this point in time) and then click on the Create a New Project option as shown in the below image.

13 of 35

Step2

The next step is to choose the project type as a Console Application. Type Console in the search bar and you will see different types of console applications using C#, and VB languages and using both .NET Framework and .NET Core / .NET. Here, I am selecting Console App (.NET Framework) using C# Language and then clicking on the Next button as shown in the below image.

14 of 35

Step3

The next step is to configure the new project. Here, you need to provide the project name and solution name. You can also give the same name to both project and solution but it is not mandatory. Here, I am providing the name MyFirstProject to both project and solution. You need to provide the location where you need to create the project. Here, you also need to provide the .NET Framework version that you want to use in this application. The latest version of the .NET Framework is 4.8. So, I am selecting .NET Framework 4.8 and then clicking on the Create button as shown in the below image.

15 of 35

Once you click on the Create button, visual studio will create the Console Application with the following structure.

A project called MYFirstProject will be created in Visual Studio. This project will contain all the necessary required files to run the Console application. The Main program called Program.cs is the default code file that is created when a new console application is created in Visual Studio. This Program.cs class will contain the necessary code for our console application. So, if you look at the Program.cs class file, then you will see the following code.

16 of 35

Step4

Now let’s write our code which will be used to display the message “Welcome to C#.NET” in the console window. To do so, modify the Main method of the Program class as shown in the below code.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace MyFirstProject

{

internal class Program

{

static void Main(string[] args)

{

Console.WriteLine("Welcome to C#.NET");

Console.ReadKey();

}

}

}

17 of 35

Step5

The next step is to run the .NET Application. To run any program in Visual Studio, you just need to click on the Start button or you can press CTRL+F5 as shown in the below image.

Once you click on the Start button, you should get the following console window showing the message.

18 of 35

Understanding the Code:

Using Visual Studio, if we are creating a console application, then automatically we are getting four sections which are shown in the below image.

19 of 35

Let’s understand each of these sections in detail.

Importing Namespace Section:

This section contains importing statements that are used to import the BCL (Base Class Libraries) as well as user-defined namespaces if required. This is similar to the included statements in the C programming language.Syntax: using NamespaceName;Example: using System;

If the required namespace is a member of another namespace, we have to specify the parent and child namespaces separated by a dot as follows:using System.Data;using System.IO;

Namespace Declaration Section:

Here a user-defined namespace is to be declared. In .NET applications, all classes related to the project should be declared inside some namespace. Generally, we put all the related classes under one namespace and in a project we can create multiple namespaces.Syntax: namespace NamespaceName {}Example: namespace MyFirstProject {}

Generally, the namespace name will be the same as the project name but it is not mandatory, you can give any user-defined name to the namespace.

20 of 35

Class Declaration Section:

This is to declare the start-up class of the project. In every .NET Desktop application like console and windows, there should be a start-up class. In the Console Application, the start-up class name is Program.cs. A start-up class is nothing but a class that contains a Main() method from which the program execution is going to start.

Syntax:class ClassName{}

Example:class Program{}

Main() Method Section:

The main() method is the entry point or starting point of the application execution. When the application starts executing, the main method will be the first block of the application be executed. The Main method contains the main logic of the application.

What is using?

Using is a keyword. Using this keyword, we can refer to .NET BCL in C# applications i.e. including the BCL namespaces as well as we can also include user-defined namespaces that we will discuss as we progress in this course. Apart from importing the namespace, other uses of using statements are there, which we will also discuss as progress in this course. For now, it is enough.

Note: In .NET the base class libraries are divided into a collection of namespaces. Each namespace contains a set of predefined classes and sub-namespaces. The namespace contains another namespace called sub-namespaces.

21 of 35

 

Syllabus B.Com(IT) - III

1

Application Development Tools(ADT) Paper – 1

  1. Introduction to Basic.NET:
  2. .NET framework Architecture
  3. Common Language Runtime (CLR)
  4. Common Type System (CTS)
  5. Common Language Specification (CLS)
  6. Just-In-Time compiler(JIT) 
  7. Framework Class Library (FCL),
  8. The role of Microsoft intermediate Language and Metadata

 

  1. Namespace.
  2. Evolution of Dot Net framework Integrated Development Environment( IDE)
  3. Variable: Declaration, Initialization,
  4. constant: Declaration, Initialization,
  5. Data type, operators: Relational, Logical, Arithmetic, Assignment, Bitwise shift operators.
  6. Creating C# Applications.

2

Active X controls

  1. Forms
  2. Text box
  3. Labels
  4. Buttons
  5. radio buttons

 

  1. Check box
  2. Timer Date
  3. Time Picker
  4. Group Box
  5. Rich Text
  6. Picture Box

Etc.

3

Control Statement : branching and Looping

Branching Statements : If – Then Statements , select case statements

Looping Statements: For – Next, For each, While – End While, Do-----loop until,

Unconditional statement: Exit statement and continue statement, procedures

4

Arrays:

Working with Arrays, Redim and preserve statement, Rectangular Array, Jagged Array, Array class

Our Syllabus

22 of 35

Program No - 1

C# Program to Check Whether a Given Number is Even or Odd

This is a C# Program to check whether the entered number is even or odd.

Problem Description

This C# Program checks if a given integer is Odd or Even.

Problem Solution

Here if a given number is divisible by 2 with the remainder 0 then the number is an Even number. If the number is not divisible by 2 then that number will be an Odd number.

Program/Source Code

Here is source code of the C# program which checks a given integer is odd or even. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

23 of 35

/*

* C# Program to Check whether the Entered Number is Even or Odd

*/

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace check1

{

class Program

{

static void Main(string[] args)

{

int i;

Console.Write("Enter a Number : ");

i = int.Parse(Console.ReadLine());

if (i % 2 == 0)

{

Console.Write("Entered Number is an Even Number");

Console.Read();

}

else

{

Console.Write("Entered Number is an Odd Number");

Console.Read();

}

}

}

}

24 of 35

Otherwise, if the condition is false then execute the else statement, for odd number the modulus of the value of ‘i’ variable by 2 is not equal to zero, if the condition is true then execute the statement and print the statement as odd number.

Runtime Test Cases

Enter a Number : 25

Entered Number is an Odd Number

Program Explanation

In this C# program, we are reading the number using ‘i’ integer variable. If condition statement is used to check the number is even and odd. For even number the modulus of the value of ‘i’ variable by 2 is equal to zero, if the condition is true then print the statement as even number.

25 of 35

C# Program to Find the Largest of Two Numbers

This is a C# Program to find greatest among 2 numbers.

Problem Description

This C# Program Finds Greatest among 2 numbers.

Problem Solution

Here the user enters two numbers and the greatest among the two numbers is found by comparing the two numbers and the result is displayed.

Program/Source Code

Here is source code of the C# Program to Find Greatest among 2 numbers. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

Program No - 2

26 of 35

/*

* C# Program to Find Greatest among 2 numbers

*/

using System;

class prog

{

public static void Main()

{

int a, b;

Console.WriteLine("Enter the Two Numbers : ");

a = Convert.ToInt32(Console.ReadLine());

b = Convert.ToInt32(Console.ReadLine());

if (a > b)

{

Console.WriteLine("{0} is the Greatest Number", a);

}

else

{

Console.WriteLine("{0} is the Greatest Number ", b);

}

Console.ReadLine();

}

}

 

Program Explanation

In this C# program, we are finding the greatest value among 2 numbers. If else condition statement is used to compare the two numbers and print the greatest value among 2 numbers.

Runtime Test Cases

 Enter the Two Numbers : 24 34 34 is the Greatest Number

27 of 35

C# Program to Swap Two Numbers

This is a C# Program to swap 2 numbers.

Problem Description

This C# Program Swaps 2 Numbers.

Problem Solution

It obtains two numbers from the user and swaps the numbers using a temporary variable.

Program/Source Code

Here is source code of the C# program that swaps two numbers. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

Program No - 3

28 of 35

29 of 35

Program Explanation

In this C# program, we are reading the numbers using ‘num1’ and ‘num2’ variables respectively. Interchange the values of the ‘num1’ and ‘num2’ variables using temporary variable ‘t’. Print the swapped value of 2 numbers.

Runtime Test Cases

Enter the First Number : 23

Enter the Second Number : 25

After Swapping :

First Number : 25

Second Number : 23

30 of 35

C# Program to Check if a Number is Divisible by 2

This is a C# Program to find whether the number is divisible by 2.

Problem Description

This C# Program Finds whether the Number is Divisible by 2.

Problem Solution

Any whole number that ends in 0, 2, 4, 6, or 8 will be divisible by 2.Here the divisibility test is done by performing the mod function with 2.

Program/Source Code

Here is source code of the C# Program to Find whether the Number is Divisible by 2. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

Program No - 4

31 of 35

32 of 35

Program Explanation

In this C# program, we are reading the number using ‘n’ variable. If condition is used to check that the modulus of the value of ‘n’ variable by 2 is equal to 0. If the condition is true then execute the statement. Print the statement as the number is divisible by 2. Otherwise, if the condition is false, then execute the else statement and print the statement as not divisible by 2.

Runtime Test Cases

Enter the Number :

45

Entered Number is Not Divisible by 2

33 of 35

C# Program to Reverse a Number

This is a C# Program to get a number and display the number with its reverse.

Problem Description

This C# Program Gets a Number and Display the Number with its Reverse.

Problem Solution

Here we obtain a number from the user and display the digits in the reverse order.

Program/Source Code

Here is source code of the C# Program to Get a Number and Display the Number with its Reverse. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

Program No - 5

34 of 35

35 of 35

Program Explanation

In this C# program, we are reading the number using ‘num’ variable. Multiply the value of ‘reverse’ variable by 10 and add this value of reverse variable with the modulus of the value of ‘reverse’ variable by 10. Compute the division of the value of ‘num’ variable by 10. Print the number with its reverse order.

Runtime Test Cases

Enter a Number : 123

Reverse of Entered Number : 321