Sub: C# and DOT NET Framework 3 Marks 1. What Is C#? Write Use of C#
Sub: C# and DOT NET Framework 3 Marks 1. What Is C#? Write Use of C#
3 marks
1. What is C#? Write Use of C#.
C# is a modern, object-oriented programming language developed by Microsoft. It is used to
create software applications that run on the .NET Framework.
Uses of C#:
Example:
class Car {
Console.WriteLine("Car is driving.");
class Program {
myCar.color = "Red";
myCar.Drive();
Encapsulation: Wrapping data (variables) and methods (functions) together into a single unit
(class) and controlling access to them using access modifiers. For example, private variables can
be accessed through public methods.
- Protected: Accessible within the same class and its derived classes.
- Protected Internal: Accessible within the same assembly and in derived classes.
5. What is ASP.NET?
ASP.NET is a web development framework by Microsoft used to build dynamic and interactive
web applications. It uses C# or VB.NET as the programming language and runs on the .NET
Framework.
Key Features:
- 2D and 3D graphics
1. Write a Features of C#
- Object-Oriented: Supports classes, objects, inheritance, polymorphism, etc.
- Rich Library: Offers a wide range of built-in libraries for various functionalities.
- Asynchronous Programming: Provides async and await for better performance in tasks
like file handling or web requests.
1.Arithmetic Operators: +, -, *, /, %
-> Arithmetic Operators are used to perform basic mathematical operations like addition (+),
subtraction (-), multiplication (*), division (/), and modulus (%).
Example:
int a = 10, b = 5;
int sum = a + b; // 15
Example:
Example:
a += b; // a = 15
Value Types:
Reference Types:
Nullable Types:
Console.WriteLine(i);
int i = 0;
while (i < 5) {
Console.WriteLine(i);
i++;
int i = 0;
do {
Console.WriteLine(i);
i++;
Example:
class Car {
public Car() {
color = "Red";
Example:
class Car {
~Car() {
Console.WriteLine("Object destroyed.");
}
Example:
class Program {
int max;
if (a > b) {
if (a > c) {
max = a;
} else {
max = c;
} else {
if (b > c) {
max = b;
} else {
max = c;
2.Page_Load: Fired when the page is loaded into the server memory.
Example:
if (!IsPostBack) {
Response.Write("Page Loaded");
}
}
8 Marks
if (x > 10) {
Console.WriteLine("Greater");
2. if-else Statement: Executes one block if the condition is true, and another if it is false.
if (x > 10) {
Console.WriteLine("Greater");
} else {
Console.WriteLine("Smaller");
if (x > 20) {
Console.WriteLine("Very Large");
Console.WriteLine("Medium");
} else {
Console.WriteLine("Small");
}
4.Switch Case: Used when multiple possible values need to be checked.
Console.WriteLine(i);
int i = 0;
while (i < 5) {
Console.WriteLine(i);
i++;
int i = 0;
do {
Console.WriteLine(i);
i++;
switch (expression) {
case value1:
break;
case value2:
break;
default:
break;
Example:
int day = 3;
switch (day) {
Output:Wednesday
Types:
ex.
class Example {
ex.
class Base {
Types of Inheritance:
2. Multilevel Inheritance: A class inherits from a class that is already a child of another class.
3. Hierarchical Inheritance: Multiple classes inherit from a single parent.
Example:
class Parent {
Console.WriteLine("Parent Class");
Console.WriteLine("Child Class");
5. Program for Object and Class. class that has two fields: id and name. It creates
instance of the class, initializesthe object and
Program:
using System;
class Student {
}
}
class Program {
student.id = 1;
student.name = "Hetal";
student.Display();
1. Common Language Runtime (CLR): Handles memory, garbage collection, and execution
of .NET programs.
2. Base Class Library (BCL): Provides built-in classes for file I/O, collections, networking, etc.
4. Application Models: Includes ASP.NET (web apps), Windows Forms, and WPF (desktop apps).
5. Cross-Platform Support: With .NET Core, applications can run on Windows, Linux, and macOS.
3. Page_Load: Load the page and its controls with user data.
Components:
1. LINQ Providers: Convert LINQ queries to the language of the data source (e.g., SQL for LINQ
to SQL).
2. Standard Query Operators: Define methods like Where, Select, and OrderBy for querying
data.
3. Expression Trees: Represent LINQ queries in a tree structure for runtime interpretation.
4. Deferred Execution: Queries are executed only when the data is accessed.
Example:
int[] numbers = { 1, 2, 3, 4, 5 };
where num % 2 == 0
select num;
Console.WriteLine(n);
Output: 2