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

C# 2MARK

The document provides an overview of C# and the .NET Framework, detailing their definitions, uses, and key components. It covers essential concepts such as CLR, CTS, CLS, and various programming constructs like data types, variables, operators, and object-oriented principles. Additionally, it discusses the differences between C# and other programming languages, as well as features like namespaces, classes, and methods.

Uploaded by

omsaidesai9
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)
3 views

C# 2MARK

The document provides an overview of C# and the .NET Framework, detailing their definitions, uses, and key components. It covers essential concepts such as CLR, CTS, CLS, and various programming constructs like data types, variables, operators, and object-oriented principles. Additionally, it discusses the differences between C# and other programming languages, as well as features like namespaces, classes, and methods.

Uploaded by

omsaidesai9
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/ 22

UNIT 1

1. Define C#?
C# is a modern, object-oriented programming language developed by
Microsoft as part of the .NET framework. It is used to build a wide variety of
applications, including web, desktop, and mobile applications.

2. Define .NET Framework?


The .NET Framework is a software development platform developed by
Microsoft that provides a comprehensive environment for building and running
applications. It includes a large class library and supports multiple
programming languages.

3. Mention some uses of .NET Framework?


.NET Framework is used for:
 Developing web applications using ASP.NET.
 Building Windows desktop applications (Windows Forms, WPF).
 Creating enterprise-level applications.
 Developing mobile applications with Xamarin.
 Supporting cloud-based services and applications.

4. State three technologies used in .NET Framework?


1. ASP.NET (for web development)
2. ADO.NET (for data access)
3. Windows Forms (for desktop applications)

5. Expand CLR? What is the use of CLR in .NET Framework?


CLR stands for Common Language Runtime. It is the runtime environment
of .NET Framework that manages the execution of code and provides services
like memory management, garbage collection, and exception handling.
6. State features of CLR?
1. Memory Management: Handles allocation and deallocation of memory
automatically.
2. Garbage Collection: Reclaims memory used by objects that are no longer
in use.
3. Exception Handling: Provides a structured way to handle runtime errors.
4. JIT Compilation: Compiles code into native code just before execution.
5. Type Safety: Ensures the correctness of types during execution.

7. State services and features of CLR?


CLR provides the following services and features:
1. Memory Management: Automatically manages the allocation and
deallocation of memory.
2. Garbage Collection: Frees up memory by reclaiming unused objects.
3. Exception Handling: Helps in handling runtime errors in a structured way.
4. Security: Provides code access security and validation.

8. Mention the main components of CLR?


1. Class Loader: Loads classes into memory.
2. JIT Compiler: Compiles Intermediate Language (IL) code into native code.
3. Garbage Collector: Reclaims memory by removing unused objects.
4. Type Safety: Ensures that data types are used correctly.
5. Exception Handling: Manages errors and exceptions during execution.
9. Expand CTS? State 2 features of CTS?
CTS stands for Common Type System.
Features:
1. Defines Data Types: Specifies how types are defined and used across
different .NET languages.
2. Ensures Interoperability: Ensures that different .NET languages can
interact by using common data types.

10. Expand CLS? State 2 features of CLS?


CLS stands for Common Language Specification.
Features:
1. Defines Language Rules: Specifies the rules for language interoperability
within the .NET environment.
2. Ensures Compatibility: Allows different .NET languages to interact and
use each other's components.

11. What is MSIL?


MSIL (Microsoft Intermediate Language) is the intermediate language code
generated by the C# compiler. It is executed by the CLR after being compiled to
native code by the Just-In-Time (JIT) compiler.
12. What is JIT?
JIT (Just-In-Time) compiler is a part of the CLR that converts MSIL code into
native machine code during the execution of the program, optimizing
performance.
13. What is Garbage Collector?
The Garbage Collector (GC) in .NET is responsible for automatically reclaiming
memory that is no longer in use, preventing memory leaks by freeing up
resources occupied by objects that are not referenced.

14. State features of Garbage Collector?


1. Automatic Memory Management: Automatically reclaims memory that
is no longer in use.
2. Prevents Memory Leaks: Ensures that objects no longer needed are
removed from memory.

15. What is Managed and Unmanaged Code?


 Managed Code: Code that runs under the control of the CLR, benefiting
from services like garbage collection and type safety.
 Unmanaged Code: Code that runs directly on the operating system,
without CLR management, such as C++.

16. What is FBL?


FBL stands for Framework BCL (Base Class Library), a collection of libraries and
classes that provide essential functionality for .NET applications, such as file I/O,
network communication, and data handling.

17. State some tasks performed by FBL?


The Framework BCL (Base Class Library) provides:
1. File Handling: For reading and writing files.
2. Data Manipulation: Includes classes for manipulating data such as
strings, arrays, and collections.
3. Network Communication: Classes to work with networking protocols.

18. Advantages or benefits of .NET approach?


1. Language Interoperability: Code written in different .NET languages can
interact seamlessly.
2. Robust Security: The .NET Framework provides built-in security features.
3. Simplified Development: Tools and libraries simplify development and
reduce time to market.

19. State Difference between C# and C++?


1. Memory Management: C# uses garbage collection, while C++ requires
manual memory management.
2. Syntax: C# is simpler and more abstracted, whereas C++ provides low-
level access to system resources.

20. State Difference between C# and Java?


1. Platform Dependency: C# is primarily used with the .NET Framework,
while Java is platform-independent and can run on any platform with a
JVM.
2. Language Features: C# has more advanced features like LINQ, while Java
focuses on core object-oriented principles.

21. State Difference between C# and Visual Basic?


1. Syntax: C# uses a C-style syntax, while Visual Basic uses a more verbose,
English-like syntax.
2. Target Audience: C# is often used by developers building large-scale
applications, while Visual Basic is used more for quick development of
Windows-based applications.

22. What is Namespace?


A namespace is a container that holds a set of identifiers, such as class names,
and allows for the organization and management of code in large applications.
23. Mention some standard namespaces in .NET?
1. System
2. System.IO
3. System.Collections
4. System.Threading

24. What is System Environment class?


The System Environment class provides information about the runtime
environment, such as system variables, environment settings, and machine
information.

25. State some important members of System Environment class?


1. GetEnvironmentVariable(): Retrieves the value of an environment
variable.
2. ExitCode: Represents the exit code of the last process that ran.

26. What is System Console class?


The System Console class provides methods for interacting with the console,
including reading input from the user and displaying output on the console.

27. State two Properties of System Console class?


1. BackgroundColor: Gets or sets the background color of the console.
2. ForegroundColor: Gets or sets the text color of the console.

28. State two methods of System Console class?


1. WriteLine(): Writes a line of text to the console.
2. ReadLine(): Reads a line of input from the console.
UNIT 2
Here are the answers with slightly more detail:
1. Explain Data Types.
Data types in C# specify the kind of data that a variable can hold, such as
integers, floats, characters, or booleans. They ensure type safety and efficient
memory usage. Common data types include int, double, char, and bool.
2. What are Variables?
Variables are containers for storing data values. Each variable in C# must be
declared with a data type before it can be used, ensuring that only compatible
data is stored in the variable.
3. What are Constants?
Constants are variables whose values are set at the time of declaration and
cannot be modified later. They are declared using the const keyword and are
used to define values that should not change, like const int MAX_VALUE = 100;.
4. Explain Operators. Name various operators.
Operators in C# are symbols that perform operations on variables and values.
Examples include:
 Arithmetic Operators: +, -, *, /, %
 Relational Operators: ==, !=, >, <
 Logical Operators: &&, ||, !
Operators are essential for manipulating data and controlling the flow of
a program.
5. List various Operators.
 Arithmetic: +, -, *, /, %
 Relational: ==, !=, >, <, >=, <=
 Logical: &&, ||, !
 Bitwise: &, |, ^, ~
 Assignment: =, +=, -=, *=, /=, %=
 Conditional: ?:
6. What are the uses of Variables?
Variables are used to store data that can change during program execution.
They help in storing inputs, temporary data, and results of computations.
7. Why are Constants used?
Constants are used to define values that remain unchanged throughout the
execution of a program. They provide clarity, prevent accidental modification,
and make the code more maintainable.
8. What is the use of Operators in C#?
Operators perform operations on variables and values, such as mathematical
calculations, comparisons, and logical evaluations, making it possible to build
expressions and control program logic.
9. Explain in Brief what are Tokens?
Tokens are the smallest elements in a C# program, including keywords,
identifiers, literals, operators, and separators. They form the basic syntax of the
language.
10. Why are Tokens used in C#?
Tokens are used to write syntactically correct programs by providing the
fundamental building blocks necessary for defining structure and behavior in
C#.
11. What are Keywords?
Keywords are reserved words in C# that have special meaning and cannot be
used as identifiers. Examples include int, class, public, and void.
12. What is Operator Precedence?
Operator precedence determines the order in which operators are evaluated in
an expression. For example, multiplication (*) has higher precedence than
addition (+), so it is evaluated first.
13. What are Conditional Statements?
Conditional statements allow the program to make decisions and execute
different blocks of code based on specific conditions. Common conditional
statements in C# are if, else if, else, and switch.
14. Why are Conditional Statements used?
Conditional statements are used to control the flow of a program by executing
certain code blocks only when specific conditions are met, making programs
dynamic and responsive.
15. Explain Flow Control Statement.
Flow control statements direct the execution order of statements in a program.
They include loops (for, while), conditional statements (if, switch), and jump
statements (break, continue).
16. What are Objects in C#?
Objects are instances of classes that encapsulate data (fields) and behavior
(methods). They represent real-world entities and provide a way to model and
interact with them in code.
17. Explain what is Lifetime of an Object?
The lifetime of an object refers to the duration for which the object exists in
memory, from its creation until it is no longer accessible and is garbage
collected by the system.
18. What is Class?
A class is a blueprint for creating objects. It defines properties, methods, and
events that its objects can use. A class encapsulates data for the object and
methods to manipulate that data.
19. Mention what Access Specifiers are?
Access specifiers define the visibility and accessibility of classes and their
members. Common specifiers include public, private, protected, and internal.
20. List various Access Modifiers.
 public: Accessible from anywhere.
 private: Accessible only within the class.
 protected: Accessible within the class and its derived classes.
 internal: Accessible within the same assembly.
 protected internal: Accessible within the same assembly and derived
classes.
21. What are Methods in C#?
Methods are blocks of code that perform specific tasks. They are defined
within classes and can be called to execute their code. Methods can accept
parameters and return values.
22. What are Static Members of a Class?
Static members belong to the class rather than any specific object. They are
shared across all instances and can be accessed using the class name instead of
an object reference.
23. Why are Constructors required in C#?
Constructors initialize objects when they are created. They set initial values for
fields and execute any startup code needed for the object to function correctly.
24. What are Destructors?
Destructors are special methods called automatically when an object is
destroyed. They are used to release resources like file handles or network
connections before the object is removed from memory.
25. What is Method Overloading?
Method overloading allows multiple methods in the same class to have the
same name but different parameters (type, number, or both). It provides
flexibility in method usage based on different input scenarios.
26. What are Literals?
Literals are fixed values used directly in code, such as numbers, characters, and
strings. For example, 42, 'A', and "Hello" are literals representing specific values.
27. What do you mean by Scope of Variables?
Scope refers to the visibility and lifetime of a variable. Variables can have local,
class-level, or global scope, determining where they can be accessed within a
program.
28. How are Expressions evaluated in C#?
Expressions are evaluated based on operator precedence and associativity. C#
follows specific rules to determine the order of evaluation to produce a final
result.
29. What is Type Conversion in C#?
Type conversion is the process of converting a variable from one data type to
another. It can be implicit (automatic conversion by the compiler) or explicit
(using casting).

UNIT 3
Here are the answers with appropriate detail:
1. What is C#?
C# is a modern, object-oriented programming language developed by
Microsoft. It is designed for building a variety of applications that run on
the .NET framework and offers features for software robustness, durability, and
productivity.
2. Name the 4 Pillars of OOP in C#.
The four pillars of Object-Oriented Programming (OOP) in C# are:
1. Encapsulation
2. Inheritance
3. Polymorphism
4. Abstraction
3. Define Encapsulation and Polymorphism.
 Encapsulation: Encapsulation is the bundling of data (fields) and
methods that operate on the data into a single unit or class. It restricts
access to the internal state and allows it to be modified only through
methods.
 Polymorphism: Polymorphism allows methods to have the same name
but behave differently based on the object that invokes them. It can be
achieved through method overriding and method overloading.
4. What are C# Class Properties? And its General Form?
Class properties in C# are special methods called accessors, which are used to
read, write, or compute the values of private fields. The general form includes
get and set accessors:
public class ClassName
{
private int field;
public int PropertyName
{
get { return field; }
set { field = value; }
}
}
5. What is Inheritance? Mention its Types.
Inheritance is a mechanism where one class (child class) derives properties and
behaviors from another class (parent class). Types of inheritance include:
 Single Inheritance
 Multilevel Inheritance
 Hierarchical Inheritance
 Multiple Inheritance (through interfaces)
6. Define Super Class and Base Class.
 Super Class: A general term for a class from which other classes inherit
properties and methods.
 Base Class: A specific term in C# used to describe the parent class in
inheritance.
7. Define Inheritance and Mention its Syntax.
Inheritance is a way to create a new class that is based on an existing class. It is
defined using the : symbol in C#:
class DerivedClass : BaseClass
{
// additional members of DerivedClass
}

8. How is Method Overriding Implemented?


Method overriding is implemented using the override keyword in a derived
class to provide a new implementation of a method defined in a base class:
class BaseClass
{
public virtual void Display() { }
}

class DerivedClass : BaseClass


{
public override void Display() { }
}
9. What is Method Hiding? Which Modifier is Used by C# for Method Hiding?
Method hiding occurs when a derived class defines a method with the same
name as a method in the base class. The new keyword is used to hide the base
class method:
class BaseClass
{
public void Display() { }
}
class DerivedClass : BaseClass
{
public new void Display() { }
}
10. What is an Abstract Class? How is it Implemented?
An abstract class is a class that cannot be instantiated and may contain abstract
methods with no implementation. It is declared using the abstract keyword:
abstract class AbstractClass
{
public abstract void AbstractMethod();
}
11. What is a Sealed Class? And Which Modifier is Used by C# for It?
A sealed class is a class that cannot be inherited. It is used to prevent further
inheritance and is declared using the sealed keyword:
sealed class SealedClass { }
12. Mention the Important Features of Interfaces.
 Define a contract that implementing classes must follow.
 Cannot contain fields or implementation code for methods.
 Support multiple inheritance.
 Declared using the interface keyword.
13. Define Boxing and Unboxing with an Example.
 Boxing: Converting a value type to a reference type.
 Unboxing: Converting a reference type back to a value type.
Int num = 123;
object obj = num; // Boxing
int unboxedNum = (int)obj; // Unboxing
14. How Many Ways Can We Call a Method in C#?
Methods can be called in the following ways:
 Directly by invoking the method on an instance.
 Using Reflection.
 Through Delegates.
15. How to Invoke Methods in C# Using Delegates?
Delegates are used to encapsulate a method reference. A delegate can be
created and used to call a method:
delegate void MyDelegate();
MyDelegate del = new MyDelegate(MethodName);
del();
16. Mention Types of Delegates.
 Single-cast Delegate: Refers to a single method.
 Multi-cast Delegate: Refers to multiple methods.
17. Mention the Ways to Declare an Event.
Events can be declared using the event keyword:
public event EventHandler EventName;
18. What is Operator Overloading?
Operator overloading allows custom definitions for the behavior of operators
for user-defined data types. It is done using the operator keyword:
public static Complex operator +(Complex c1, Complex c2) { }
19. What are C# Events?
C# events are mechanisms for communication between objects, allowing one
object to notify others about state changes. They are based on delegates and
are declared using the event keyword.

UNIT 4
Here are the concise answers:
1. Define Types of Error.
Errors in programming are generally classified into:
 Syntax Errors: Mistakes in code syntax.
 Runtime Errors: Errors occurring during program execution.
 Logical Errors: Flaws in the program's logic leading to incorrect results.
2. List Some of the Purpose of Exception Handling.
 Gracefully handle errors.
 Maintain program flow without crashing.
 Provide meaningful error messages to users.
 Log errors for debugging purposes.
3. Give the Syntax of Exception Handling.
try
{
// Code that may throw an exception
}
catch (ExceptionType e)
{
// Handle the exception
}
finally
{
// Code that executes after try or catch
}

4. What is Multiple Catch Block?


Multiple catch blocks allow handling different types of exceptions separately
within a try block:
try { }
catch (FormatException e) { }
catch (InvalidOperationException e) { }
5. What is Finally Block?
The finally block contains code that is always executed after the try and catch
blocks, regardless of whether an exception occurred.
6. What Does "throw" Keyword Do in a Program?
The throw keyword is used to explicitly throw an exception in a program:
throw new Exception("Error occurred");
7. Define Types of Exception.
 System Exceptions: Provided by .NET, such as DivideByZeroException.
 Application Exceptions: Custom exceptions created by the user.
8. What is Object Lifetime?
Object lifetime refers to the duration from an object's creation to its garbage
collection. It involves allocation, usage, and deallocation of memory.
9. Show the Relationship Between Class, Object, and Reference.
 Class: A blueprint for creating objects.
 Object: An instance of a class.
 Reference: A variable that holds the memory address of an object.
10. What is the Golden Rule of .NET Memory Management?
The golden rule is to avoid manual memory management. Let the garbage
collector handle memory cleanup to prevent memory leaks and ensure
efficient resource management.

11. How Does System.GC Work?


System.GC manages garbage collection, automatically freeing memory
occupied by objects that are no longer in use. It can also be invoked manually
using System.GC.Collect().
12. Define Assemblies.
Assemblies are compiled code units in .NET, containing metadata and
intermediate language code (IL). They can be executables (.exe) or libraries (.dll)
and are the building blocks of .NET applications.

UNIT 5
Here are the answers with concise explanations:
1. Define List.
A List in C# is a collection that can dynamically grow or shrink in size, allowing
storage of elements that can be accessed by index.
2. What are the Types of Collections?
 ArrayList
 List
 Dictionary
 HashSet
 Queue
 Stack
3. Write a Syntax to Create ArrayList.
ArrayList arrayList = new ArrayList();
4. Define Hash Table.
A HashTable is a collection that stores key-value pairs, where each key is
unique and used to access its corresponding value.
5. Define IDE.
An Integrated Development Environment (IDE) is a software application that
provides comprehensive facilities for software development, such as code
editor, debugger, and build automation tools.
6. Write Different IDE Modes.
 Design Mode: Used for designing the UI.
 Run Mode: Executes the application.
 Debug Mode: Allows debugging of the code.
7. Define Toolbar.
A Toolbar is a graphical control element that contains buttons, icons, or menus
for quick access to commonly used functions in an application.
8. What are Generic Classes?
Generic Classes in C# are classes defined with a type parameter, allowing the
same class to be used with different data types:
class GenericClass<T>
{
public T Data { get; set; }
}
9. Define Form.
A Form is a window or screen in a graphical user interface that acts as a
container for controls like buttons, textboxes, and labels.
10. What is Event?
An Event is an action or occurrence detected by a program, often from user
input, such as a mouse click or key press.
11. What is TextBox?
A TextBox is a control that allows users to input text in a form.
12. Write Any Two Properties of TextBox Control.
 Text: Gets or sets the text in the TextBox.
 MaxLength: Sets the maximum number of characters allowed.
13. Write Types of Items in Menu Strip.
 Menu Items
 Submenu Items
 Separator
14. Write Types of Items in Context Menu Strip.
 Context Menu Items
 Submenu Items
 Separator

15. What is Comparing Sorting?


Comparing Sorting involves arranging elements in a collection based on
comparisons between elements, such as ascending or descending order.
16. Define ToolStrip.
A ToolStrip is a flexible container for holding items such as buttons, labels, and
separators in a strip, often used for toolbars in applications.
17. Define GDI, SDI, MDI.
 GDI: Graphics Device Interface - Used for rendering graphics in
applications.
 SDI: Single Document Interface - Supports one document at a time.
 MDI: Multiple Document Interface - Supports multiple documents in
separate windows within the same parent window.
18. Give Syntax of Form Creation.
Form myForm = new Form();
19. Expand GDI, SDI, MDI.
 GDI: Graphics Device Interface
 SDI: Single Document Interface
 MDI: Multiple Document Interface

You might also like