0% found this document useful (0 votes)
20 views15 pages

Sub: C# and DOT NET Framework 3 Marks 1. What Is C#? Write Use of C#

The document provides an overview of C# and the .NET Framework, detailing its features, uses, and key concepts such as classes, objects, data abstraction, encapsulation, and access modifiers. It also covers ASP.NET, LINQ, WPF, and various programming constructs including control structures, polymorphism, and inheritance. Additionally, it explains the .NET architecture, page life cycle in ASP.NET, and provides examples of C# programming.

Uploaded by

tanviladva01
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)
20 views15 pages

Sub: C# and DOT NET Framework 3 Marks 1. What Is C#? Write Use of C#

The document provides an overview of C# and the .NET Framework, detailing its features, uses, and key concepts such as classes, objects, data abstraction, encapsulation, and access modifiers. It also covers ASP.NET, LINQ, WPF, and various programming constructs including control structures, polymorphism, and inheritance. Additionally, it explains the .NET architecture, page life cycle in ASP.NET, and provides examples of C# programming.

Uploaded by

tanviladva01
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/ 15

Sub : C# and DOT NET Framework

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#:

- Building Windows applications

- Developing web applications using ASP.NET

- Creating mobile applications using Xamarin

- Game development using Unity

- Working with cloud and IoT applications

2. Define Class and Object with Example:


Class: A class is a blueprint or template that defines the structure and behavior (properties and
methods) of objects.

Object: An object is an instance of a class that represents a real-world entity.

Example:

class Car {

public string color;

public void Drive() {

Console.WriteLine("Car is driving.");

class Program {

static void Main() {


Car myCar = new Car();

myCar.color = "Red";

myCar.Drive();

3. Explain Data Abstraction and Encapsulation:


Data Abstraction: Hiding the complex details and showing only the essential features of an
object. For example, a car’s steering lets you drive without needing to know how the engine
works.

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.

4. Explain Access Modifier in Details:


Access modifiers control the visibility of classes, methods, and variables:

- Public: Accessible from anywhere.

- Private: Accessible only within the same class.

- Protected: Accessible within the same class and its derived classes.

- Internal: Accessible within the same assembly.

- 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:

- Easy integration with databases

- Built-in security features

- High performance and scalability

6. Write Advantage of LINQ:


Provides a simple way to query data from various sources (e.g., databases, XML, collections).

- Eliminates the need for complex SQL queries.

- Improves code readability and maintainability.

- Offers compile-time checking and IntelliSense support.

7. Give A FullForm of: 1) LINQ 2)WPF 3)WCF


LINQ: Language Integrated Query

WPF: Windows Presentation Foundation

WCF: Windows Communication Foundation

8. Describe Windows Presentation Foundation:


WPF is a framework for building rich desktop applications in Windows. It uses XAML for
designing user interfaces and supports features like:

- 2D and 3D graphics

- Data binding for dynamic content

- Animation and multimedia integration

- Flexible layout options


4 Marks

1. Write a Features of C#
- Object-Oriented: Supports classes, objects, inheritance, polymorphism, etc.

- Type-Safe: Prevents type errors during compile time.

- Garbage Collection: Automatically manages memory by cleaning unused objects.

- Platform Independence: Runs on multiple platforms with .NET Core.

- 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.

2. Explain Operators in Details:


Operators are symbols used to perform operations on variables and values.

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

2. Relational Operators: >, <, >=, <=, ==, !=

Example:

bool isEqual = (a == b); // false

3. Logical Operators: &&, ||, !

Example:

if (a > 5 && b < 10) { Console.WriteLine("Condition met."); }

4. Assignment Operators: =, +=, -=, *=, /=, %=


Example:

a += b; // a = 15

3. Explain Data Type in C# with Suitable Example:


Data types define the type of data a variable can hold.

Value Types:

Examples: int, float, double, char, bool

int age = 25;

float height = 5.9f;

Reference Types:

Examples: string, array, class

string name = "Hetal";

Nullable Types:

Allows value types to accept null values.

int? marks = null;

4. Explain Looping Statement in C#:


For Loop: Executes a block of code a specific number of times.

for (int i = 0; i < 5; i++) {

Console.WriteLine(i);

While Loop: Executes as long as the condition is true.

int i = 0;

while (i < 5) {
Console.WriteLine(i);

i++;

Do-While Loop: Executes at least once before checking the condition.

int i = 0;

do {

Console.WriteLine(i);

i++;

} while (i < 5);

5. Explain Constructor and Destructor with Example:


Constructor: A special method in a class that initializes objects.

Example:

class Car {

public string color;

public Car() {

color = "Red";

Destructor: A method that cleans up resources when an object is destroyed.

Example:

class Car {

~Car() {

Console.WriteLine("Object destroyed.");
}

6. What is Entity Framework? How to Access Data in ORM:


Entity Framework (EF) is an Object-Relational Mapping (ORM) framework for accessing
databases using C#.

How Data Access Works:

- Use LINQ to perform CRUD operations.

- Define a model class for database tables.

Example:

using (var context = new MyDbContext()) {

var data = context.Students.ToList();

7. Write a c# program to find maximum value of given 3 static value


using System;

class Program {

static void Main() {

int a = 10, b = 20, c = 15; // Static values

int max;

if (a > b) {

if (a > c) {

max = a;

} else {
max = c;

} else {

if (b > c) {

max = b;

} else {

max = c;

Console.WriteLine("The maximum value is: " + max);

8. Explain Page Events in Detail:


Page events in ASP.NET handle the lifecycle of a web page.

1.Page_Init: Fired when the page is initialized.

2.Page_Load: Fired when the page is loaded into the server memory.

3.Page_PreRender: Fired just before the page renders on the browser.

4.Page_Unload: Fired when the page finishes rendering and is unloaded.

Example:

protected void Page_Load(object sender, EventArgs e) {

if (!IsPostBack) {

Response.Write("Page Loaded");

}
}

8 Marks

1. Write a Control structure in details.


=> Condition Statements:

These structures execute specific blocks of code based on a condition.

1.if Statement: Executes a block if the condition is true.

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");

3. else if Ladder: Tests multiple conditions sequentially.

if (x > 20) {

Console.WriteLine("Very Large");

} else if (x > 10) {

Console.WriteLine("Medium");

} else {

Console.WriteLine("Small");

}
4.Switch Case: Used when multiple possible values need to be checked.

=> Looping Statements: Repeat a block of code.

1.For Loop: Executes a block a fixed number of times.

for (int i = 0; i < 5; i++) {

Console.WriteLine(i);

2.While Loop: Repeats as long as the condition is true.

int i = 0;

while (i < 5) {

Console.WriteLine(i);

i++;

3.Do-While Loop: Executes the block at least once.

int i = 0;

do {

Console.WriteLine(i);

i++;

} while (i < 5);

=> Jump Statements:

break: Exits the loop or switch case.

continue: Skips the current iteration and moves to the next.

goto: Jumps to a labeled statement.

2. Describe Switch Statements with Example


A switch statement selects one option from multiple cases based on a value.
Syntax:

switch (expression) {

case value1:

// Code for case 1

break;

case value2:

// Code for case 2

break;

default:

// Code for no match

break;

Example:

int day = 3;

switch (day) {

case 1: Console.WriteLine("Monday"); break;

case 2: Console.WriteLine("Tuesday"); break;

case 3: Console.WriteLine("Wednesday"); break;

default: Console.WriteLine("Invalid day"); break;

Output:Wednesday

3. Explain Polymorphism with Its Type:


Polymorphism means “many forms,” allowing the same function or object to behave differently
in different contexts.

Types:

1.Compile-Time Polymorphism (Method Overloading):

Multiple methods with the same name but different parameters.

ex.

class Example {

void Display(int a) { Console.WriteLine(a); }

void Display(string a) { Console.WriteLine(a); }

2.Run-Time Polymorphism (Method Overriding):

A derived class provides a specific implementation of a method in the base class.

ex.

class Base {

public virtual void Show() { Console.WriteLine("Base class"); }

class Derived : Base {

public override void Show() { Console.WriteLine("Derived class"); }

4. Explain Inheritance with Its Types


Inheritance allows a class (child) to use properties and methods of another class (parent).

Types of Inheritance:

1. Single Inheritance: One child inherits from one parent.

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.

4. Multiple Inheritance: Supported through interfaces, where a class implements multiple


interfaces.

Example:

class Parent {

public void Show() {

Console.WriteLine("Parent Class");

class Child : Parent {

public void Display() {

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 {

public int id;

public string name;

public void Display() {

Console.WriteLine($"ID: {id}, Name: {name}");

}
}

class Program {

static void Main() {

Student student = new Student();

student.id = 1;

student.name = "Hetal";

student.Display();

Output: ID: 1, Name: Hetal

6. Explain .NET Architecture in Details


.NET is a platform for building applications. Its architecture includes:

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.

3. Languages: Supports C#, VB.NET, and F#.

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.

7. Write A Page Life Cycle In details


The ASP.NET Page Life Cycle describes the steps a web page goes through from the time it is
requested by the user to the time it is sent back to the browser. Each stage has specific tasks,
and understanding these helps in writing better web applications.
1. Page_PreInit: Customize page settings like themes and master pages.

2. Page_Init: Initialize controls and view state.

3. Page_Load: Load the page and its controls with user data.

4. Page_PreRender: Make final updates before rendering the page.

5. Page_Unload: Clean up resources after rendering.

8. Describe Architecture of LINQ


LINQ (Language Integrated Query) is designed to query data from different sources.

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 };

var evenNumbers = from num in numbers

where num % 2 == 0

select num;

foreach (var n in evenNumbers) {

Console.WriteLine(n);

Output: 2

You might also like