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

Unit 1

Unit 1 of .net

Uploaded by

ixiixi439
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 views5 pages

Unit 1

Unit 1 of .net

Uploaded by

ixiixi439
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/ 5

Unit I: Introduction to C#

1. Introduction to C#

 What is C#?

o C# is a modern, object-oriented, type-safe programming language developed by


Microsoft.

o Designed for developing applications on the .NET platform.

o Combines simplicity, expressiveness, and flexibility.

 Features of C#:

o Strongly Typed: Ensures type safety.

o Automatic Garbage Collection.

o Rich Standard Library.

o Language-Integrated Query (LINQ) for database integration.

o Cross-Platform Development using .NET Core.

2. Common Language Runtime (CLR)

 Definition:

o The CLR is the runtime environment of the .NET Framework.

o It provides services like memory management, exception handling, and security.

 Key Responsibilities:

o Garbage Collection: Automatically manages memory.

o Type Safety: Ensures code adheres to type-checking rules.

o Intermediate Language (IL) Execution: Compiles C# code to IL and executes it via


Just-In-Time (JIT) Compilation.

o Exception Handling: Manages runtime errors.

o Cross-Language Interoperability: Allows different .NET-supported languages to work


together.

3. Visual Studio and Console Applications

 Visual Studio:

o Integrated Development Environment (IDE) for .NET.

o Features include IntelliSense, debugging tools, and project templates.

 Creating a Console Application:


1. Open Visual Studio.

2. Select File > New > Project.

3. Choose Console App (.NET).

4. Write C# code in Program.cs.

5. Run the program using the "Run" button or Ctrl + F5.

 Sample Code:

using System;

class Program

static void Main(string[] args)

Console.WriteLine("Hello, World!");

4. Simple Windows Forms

 Definition:

o Windows Forms (WinForms) is a GUI toolkit for creating desktop applications.

 Creating a Windows Forms App:

1. Open Visual Studio.

2. Choose Windows Forms App (.NET).

3. Design the interface using drag-and-drop tools.

4. Write event-handling code for components like buttons and textboxes.

 Example Code (Button Click Event):

private void btnClickMe_Click(object sender, EventArgs e)

MessageBox.Show("Button Clicked!");

5. C# Language Fundamentals
 Variables and Data Types:

o Common data types: int, float, double, string, bool, etc.

o Example:

int number = 10;

float price = 99.99f;

string name = "C# Basics";

bool isAvailable = true;

 Control Structures:

o Conditional Statements: if, else, switch.

o Loops: for, while, do-while, foreach.

 Functions and Methods:

o Syntax:

csharp

Copy code

returnType MethodName(parameters)

// method body

 Example:

static int Add(int a, int b)

return a + b;

6. Enumerations (Enums)

 Definition:

o Enums are a way to define named constant values.

 Syntax:

enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };

 Example Usage:

Days today = Days.Monday;


Console.WriteLine($"Today is {today}");

7. Structures

 Definition:

o Structures are value types that can encapsulate data and related functionality.

 Syntax:

struct Point

public int X;

public int Y;

public Point(int x, int y)

X = x;

Y = y;

 Example Usage:

Point p = new Point(10, 20);

Console.WriteLine($"Point: ({p.X}, {p.Y})");

8. Namespaces

 Definition:

o Namespaces organize code and prevent naming conflicts.

 Common Syntax:

namespace MyNamespace

class MyClass

public void Greet()

{
Console.WriteLine("Hello from MyNamespace!");

 Using a Namespace:

using MyNamespace;

class Program

static void Main()

MyClass obj = new MyClass();

obj.Greet();

You might also like