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

Unit-1 .Net Framework And C# Programming

Uploaded by

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

Unit-1 .Net Framework And C# Programming

Uploaded by

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

.

Net Framework and C# Programming


UNIT-1
Introduc on to C#

 It is one of the most popular programming languages in the world.


 It is an object-oriented programming language created by Microso that runs on the .NET Framework.
 C# has roots from the C family, and the language is close to other popular languages like C++ and Java.
 The first version was released in year 2002. The latest version, C# 12, was released in November 2023.
 It is widely used for building Mobile applica ons, Desktop applica ons, Web applica ons, Web services, Web
sites, Games, VR, Database applica ons and much, much more!
 It is easy to learn and simple to use.
 It has huge community support.
 C# is an object-oriented language which gives a clear structure to programs and allows code to be
reused, lowering development costs.
 C# is close to C, C++ and Java, it makes it easy for programmers to switch to C# or vice versa.

Code
using System;
namespace HelloWorldApp {
class First {
sta c void Main(string[] args) {
Console.WriteLine("Hello World!");
}
}
}

Introduc on to .NET Framework

The .NET Framework is a so ware development framework developed by Microso that provides a run me
environment and a set of libraries and tools for building and running applica ons on Windows opera ng systems. The
framework includes a variety of programming languages, such as C#, F#, and Visual Basic, and supports a range of
applica on types, including desktop, web, mobile, and gaming applica ons.

1. The .NET Framework includes two main components: the Common Language Run me (CLR) and the .NET
Framework Class Library. The CLR is responsible for managing the execu on of code wri en in any of the
supported languages, while the class library provides a large set of pre-built func ons and classes that can be
used to create a wide range of applica ons.
2. The .NET Framework also provides a number of features that help improve the security, reliability, and
performance of applica ons. These include features such as code access security, automa c memory
management, and just-in- me (JIT) compila on, which helps improve the speed of applica on execu on.
3. The .NET Framework is also designed to integrate with other Microso technologies, such as Microso SQL
Server, Microso SharePoint, and Microso Office, which can make it easier to build applica ons that work
seamlessly with other Microso products.

Overall, the .NET Framework is a powerful and versa le development pla orm that provides a wide range of tools and
libraries for building and running applica ons on Windows opera ng systems.
.NET Framework supports more than 60 programming languages of which 11 programming languages are designed and
developed by Microso . The remaining Non-Microso Languages are supported by .NET Framework but not designed
and developed by Microso .
Common Language Run me (CLR)
The Common Language Run me (CLR) is a component of the Microso .NET Framework that manages the execu on
of .NET applica ons. It is responsible for loading and execu ng the code wri en in various .NET programming
languages, including C#, VB.NET, F#, and others.

When a C# program is compiled, the resul ng executable code is in an intermediate language called Common
Intermediate Language (CIL) or Microso Intermediate Language (MSIL). This code is not machine-specific, and it can
run on any pla orm that has the CLR installed. When the CIL code is executed, the CLR compiles it into machine code
that can be executed by the processor.

The CLR provides many services to .NET applica ons, including memory management, type safety, security, and
excep on handling. It also provides Just-In-Time (JIT) compila on, which compiles the CIL code into machine code on
the fly as the program runs, op mizing performance.

Addi onally, the CLR provides a framework for developing and deploying .NET applica ons, including a set of libraries,
called the .NET Framework Class Library, which provides access to a wide range of func onality, such as input/output
opera ons, networking, database connec vity, and user interface design.

Overall, the CLR is a cri cal component of the .NET Framework and is responsible for ensuring that .NET applica ons
are executed in a safe, secure, and efficient manner, making it a fundamental aspect of C# programming.

Visual Studio Console App


What is Visual Studio?
Visual Studio is an integrated development environment (IDE) developed by Microso . It is a comprehensive tool used
by developers to create applica ons for Windows, web, mobile, and cloud pla orms. Visual Studio supports a variety
of programming languages, frameworks, and tools, making it one of the most powerful and versa le IDEs available.

Crea ng a Console App in Visual Studio


1. Start Visual Studio 2022.
2. On the start page, choose Create a new project.
3. On the Create a new project page, enter console in the search box. Next, choose C# or Visual Basic from the
language list, and then choose All pla orms from the pla orm list. Choose the Console Applica on template,
and then choose Next.
4. In the Configure your new project dialog, enter Project name and Loca on for your project. Then
choose Next.
5. In the Addi onal informa on dialog, select .NET 8.0 (Long-term support), and then select Create.

Simple Windows Forms

What are Windows Forms?


Windows Forms (commonly known as WinForms) is a graphical user interface (GUI) framework provided by Microso
to create desktop applica ons for Windows. It's part of the .NET framework and allows developers to design
applica ons with a variety of controls like bu ons, text boxes, labels, and more, enabling interac on between the user
and the applica on.
Crea ng a Simple Windows Form
1. Start Visual Studio 2022.
2. On the start page, choose Create a new project.
3. On the Create a new project page, enter Windows Forms App in the search box. Next, choose C# from the
language list, and then choose Windows from the pla orm list. Choose the Windows Forms App (.NET
Framework) template, and then choose Next.
4. In the Configure your new project dialog, enter Project name and Loca on for your project and choose the
appropriate Framework. Then choose Create.

Enumera ons
Enumera on (Enum) is a special "value type" that allows us to define a set of named constants such as season, days,
month, size etc. Enums are useful when we have a collec on of related values and want to work with them in a more
readable and structured way. Enums make code more understandable and reduce errors, especially when dealing with
fixed sets of values. The Enum constants are also known as enumerators. Enum in C# can be declared within or outside
class and structs. Enum constants has default values which starts from 0 and incremented to one by one. But we can
change the default value.
C# code for Enumera on: -
using System;
namespace Example {
class Program {
enum Days {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};
public sta c void Main(string[] args){
Console.WriteLine("The value of Sunday in Days " + (int)Days.Sunday);
Console.WriteLine("The value of Monday in Days " + (int)Days.Monday);
Console.WriteLine("The value of Friday in Days " + (int)Days.Friday);
}
}
}

Structures
Structure is a value type and a collec on of variables of different data types under a single unit. It is almost similar to a
class because both are user-defined data types and both hold a bunch of different data types. Structs are used to create
lightweight objects that are typically smaller, simpler, and o en more efficient in memory compared to classes. Unlike
classes, structures are stored on the stack rather than the heap, making them ideal for small data types where
performance is cri cal.
C# code for Structure: -
using System;
namespace ConsoleApplica on{
class Geeks{
public struct Person{
public string Name;
public int Age;
public int Weight;
}
sta c void Main(string[] args)
{
Person P1;
P1.Name = "Keshav Gupta";
P1.Age = 21;
P1.Weight = 80;
Console.WriteLine("Data Stored in P1 is " + P1.Name + ", age is " +
P1.Age + " and weight is " +
P1.Weight);
}
}
}
Namespaces
Namespaces are used to organize the classes. It helps to control the scope of methods and classes in larger .Net
programming projects. In simpler words you can say that it provides a way to keep one set of names(like class names)
different from other sets of names. The biggest advantage of using namespace is that the class names which are
declared in one namespace will not clash with the same class names declared in another namespace. It is also referred
as named group of classes having common features. The members of a namespace can be namespaces, interfaces,
structures, and delegates.
C# code for Namespace: -
using System;
namespace First {
public class Hello
{
public void sayHello() { Console.WriteLine("Hello First Namespace"); }
}
}
namespace Second
{
public class Hello
{
public void sayHello() { Console.WriteLine("Hello Second Namespace"); }
}
}
public class TestNamespace
{
public sta c void Main()
{
First.Hello h1 = new First.Hello();
Second.Hello h2 = new Second.Hello();
h1.sayHello();
h2.sayHello();

}
}

You might also like