You are on page 1of 24

KUVEMPU UNIVERSITY 6th SEM Sample Paper

BASICS OF .NET
Long question answer
1. What is .NET frame work? Explain.
Ans:- The .NET framework is one of the tool provided by Microsoft corporation. T
his is a software framework that includes everything required for developing sof
tware for web services. The .NET platform provides a new environment for creatin
g and running robust, scalable and distributed application over the web. It is d
esigned to make significant improvements in code reuse, code specialization, res
ource management, and Multilanguage development.
It consists of three services:
a).NET Product: It consists of Visual Studio .NET, Visual Basic, Visual C#, and
Visual C++.
b) .NET Services: .NET helps you to create software as a web services. Microsoft
has its own set of web services called My Services.
c) .NET framework: It is a foundation on which you design, develop, and deploy a
pplications. It is consistent and simplified programming model that helps you to
easily build robust application.
.Net framework has several components such as Window form, Console application,
Web forms and web services, Base class library and Common language runtime.
2. What are the advantages of using .NET frame work?
Ans: Following are the main advantages of .NET framework:
Consistent programming model:- It provide a common object-oriented programmi
ng model across languages. This object model can be used to perform several task
s such as reading from and writing to file, connecting to databases, and retriev
ing data.
Multi-platform application:- A .NET application can execute on any architect
ure or environment that is supported by the CLR.
Multi-language integration:- .NET allow multiple language to be integrated.
We can create a object in any language that is derived from a class implemented
in any other languages. To enable objects to interact with each other a set of
language features has been defined in CLS. CLS enhances language interoperabilit
y.
Automatic resource management: CLR is a important component of .NET framework
. It manages all resources such as file, memory, network connection, and databas
e resources automatically without writing the code.
Ease of development: .NET applications can be deployed simply by copying fil
es to the target computer. The .NET framework provides zero-impact deployment me
ans that installation of new applications or components does not have an adverse
effect on the existing applications.
Web services:- With the advent of .NET technology, web services provide many
built in Base Class Library facility which open up a whole world of information
for the users. Web services provide everything from basic text news information
to vital database or application information.
3. How does string handle in C# ? Explain.

Ans: String is a sequence of characters. It is the easiest way to represent a se


quence of characters in C#. In C# string is uses to create a string type object
s. It is an alias to the System.String type. String type is immutable means that
once it has been created, a string cannot be changed. No modification in the st
ring will take place. Ex: Insert () method of string class

using System;
class str

public static void Main()


string s1 =

Lean ;

string s2 = s1.Insert ( 3,

r );

string s3 = s1.Insert (5,

er );

for (int I =0; i>s3.Length; i++ )

Console.Write(s3[i]);
Console.WriteLine();
}}

4. Explain working of switch statement.


Ans: A switch statement executes the statements that are associated with the val
ue of a given expression. It checks the values of a given variable against a lis
t of case values and when a match is found, a block of statements associated wit
h that case is executed.
Following example demonstrate the working of switch statement:

using System;
class CityGuide {
public static void Main() {
Console.WriteLine(

Select your choice );

Console.WriteLine( London );
Console.WriteLine( Bombay );
Console.WriteLine( Paris );
Console.WriteLine(

Type your choice );

String name = Console.ReadLine();

switch (name)
case

Bombay :

Console.WriteLine(

Bombay: guide 5 );

break;
case London :
Console.WriteLine(

London: guide 10 );

break;
case Paris :
Console.WriteLine(

Paris: guide 12 );

break;
default:
Console.WriteLine(

Invalid choice );

break;
}}}
5. Write an ASP. NET program to demonstrate handling of server control events.
Ans: Server control is capable of exposing an object model containing properties
, methods and events in ASP.NET. Developers use this object model to cleanly mod
ify and interact with the page.
Following program shows the handling of server control event:-

Name:
Category:
Math
English
Science

6. Compare the features of C++ with C# programming.


Ans: i) C++ support object-oriented programming while C# is purely object-orient
ed language.
ii) The syntax for declaring array follows the token
from C++.

[]

in C# which is different

iii) There is no conversion between the bool type and int in C#.
iv) In C#, the long data type is 64 bits, while in C++, it is 32 bits.
v) C# supports additional operator such as is and typeof while C++ doesn t support
s them.
vi)C# strings are different from C++ string.
vii) In C# Main method is declared differently from the main function in C++.
viii) Like C++, no header files or #include directives in C#.
ix) Operator overloading is performed differently in C# from C++.
x) Unlike C++, if you don t provide a class constructor in C#, a default construct
or is automatically generated for.

7. Explain how to use multiple threads in program with example.


Ans: Following code shows the use of multithread in program:-

using System;
using System.Threading;
class threads {
public static void ChildThread1() {
Console.WriteLine( This is child thread );
Console.WriteLine( child thread- counting from 1to 5 );
for (int T=1; T
for (int Cnt=0; Cnt
Console.Write( . ); }
Console.Write( {0} ,

T);

Console.WriteLine( child thread ending ); }


Public static void ChildThread2() {
Console.WriteLine( This is child thread2 );

Console.WriteLine( child thread2- counting from 6 to 10 );


for (int T=6; T
for (int Cnt=0; Cnt
Console.Write( . ); }
Console.Write( {0} ,

T);

Console.WriteLine( child thread2 ending );

Public static void Main() {


ThreadStart Child1 = new ThreadStart (ChildThread1);
ThreadStart Child2 = new ThreadStart (ChildThread2);
Console.WriteLine( This is creating child thread );
Thread Thread1 = new Thread(Child1);
Thread Thread2 = new Thread(Child2);
Thread1.Start();
Thread2.Start(); }}

8. What are the advantages of using multiple threads in program?


Ans: Threads are the basic unit to which an operating system allocates processor
time, and more than one thread can run inside that process. Each thread maintai
ns exception handlers, a scheduling priority, and a set of structures the system
uses to save the thread context until it is scheduled.
Multithreading offers the following advantages:
i)Improved responsiveness: If the application is performing operations that take
a perceivably long time to complete, these operations can be put into a separat
e thread which will allow the application to continue to be responsive to the us
er.
ii) Faster application: Multiple threads can lead to improved application perfor
mance. For example, if there are a number of calculations to be performed, then
there the application can be made faster by performing multiple operations at th
e same time.
iii) Prioritization: Threads can be assigned a priority which would allow higher
priority tasks to take precedence over lower priority tasks.
iv) It communicates over a network, to a web server and to a database.
9. a) Explain exception handling techniques.
Ans: An exception is any error condition or unexpected behavior encountered by a
program in execution. Exception can be raised because of fault in our code or s
hared library.

Exceptions are handled by a try statement. When an exception occurs, the system
searched for the nearest catch block that can handle the exception. Once a match
ing catch block is found the control is transferred to the first statement of th
e catch block and the catch block executes. If no matching catch block is found,
then the execution of the thread is terminated. Some exception objects are- Sys
tem.AirthmeticException, System.DivideByZeroException.
10. Write a program in C # to display
ram?

Welcome to World of C sharp

Explain the prog

Ans:- using System;


namespace Welcome
{
class Hello
{
public static void Main()
{
Console.WriteLine( Welcome to the world of C Sharp ); }}}
11. Explain how to create user defined exceptions with an example.
Ans: User defined exception classes are derived from the ApplicationException cl
ass. Following code creates a user defined exception named CountIsZeroException.

using System;
namespace UDExc

class CountZero {
public static void Main(string[] args) {
Calcute calc = new Calcute();
Try {
Calc.DoAverage(); }
Catch (CountIsZeroException e) {
Console.WriteLine( CountIsZeroException: {0} ,e.Message); }
Console.ReadLine(); }}}
Public class CountIsZeroException: ApplicationException {
Public class CountIsZeroException(string message) : base (message) { }}
Public class Calculate {

Int sum = 0;
Int count = 0;
Float average;
Public void Doaverage() {
If (count === 0)
Throw (new CountIsZeroException( zero count in average ) );
Else average = sum/count; }}

12. What is .NET framework? Explain architecture of .NET frame work.


Ans: The .NET framework is one of the tools provided by Microsoft Corporation. T
his is a software framework that includes everything required for developing sof
tware for web services. The .NET platform provides a new environment for creatin
g and running robust, scalable and distributed application over the web. It is d
esigned to make significant improvements in code reuse, code specialization, res
ource management, and Multilanguage development.
Architecture of .NET framework:.NET Framework
VB.NET C#
Jscript.NET
Other .NET language
ASP .NET
(Web Services)
Widows Forms (User Interface)
ADO .NET

Console

.NET Remoting
Framework Class library
Common Language Runtime

i)It consists of several languages and web services such as C#, VB.Net, Jscript.
Net, ASP.Net, ADO.Net etc.
Operating System
ii) Common Language Runtime: This is the most essential component of the .Net fr
amework. It is the environment where all programs using .Net are executed. It pr
ovides services such code compilation memory allocation, and garbage collection.
It also provides a set of rule known as CTS.
iii) Framework class Library: This library works with any .Net languages. It pro
vides classes that can be used in the code to accomplish a range of common progr
amming tasks such as string management, data collection, database connectivity e
tc.
b) What is the use of attributes in C# programs?
Ans: Attribute is declarative tag that is used to convey information to runtime
about the behavior of programmatic element such as classes, enumeration and asse
mblies. Attributes are used for adding metadata. Attributes are applied to diffe
rent element of the code. Attributes might require one or more parameter. Some p
redefined attribute used by C# are:- i) Conditional:- It causes conditional com

pilation of method calls, depending on specified value.


ii) WebMethod:- It identifies the exposed method in a web service.
iii) DllImport:- It calls an unmanaged code in programs developed outside the .N
et environment.
iv) Obsolete:- It enables programmer to inform the compiler to discard a piece o
f element like method of a class.

13. What is the function of CTS? Explain the classification of types in CTS with
a diagram?
Ans: Functions of CTS are:
i) Establishing a common framework that enables cross
language integration, type safety, and high performance code execution. ii) Pro
viding an object-oriented model. iii) Defining rules that languages must follows
, so that different languages can interact with each other.
Type
Types in CTS:Value Types
Reference Types
Built-in Value Types
User-Defined Value Types
Enumeration
Self Describing
s
Pointer
Interface
Class Types
Arrays
User-Defined Classes
Boxed Value Types
Delegates

Type

Reference type:Value type:14.a) What is operator overloading? Explain with an example.


Ans: Operator overloading is a way that allows operator to work with user define
d data type in the same way as the built-in data types. It provides a flexible o
ption for the creation of new operator definitions in C#.

Example: Code for overloading minus (-) operator:


using System;
class Calculator {
public int number1, number2;
public Calculator(int num1, int num2) {
number1=num1;
number2=num2; }
public static Cclculator operator

(Calculator c1) {

c1.number1 = -c1.number1;
c1.number2 = -c1.number2;
return c1;

public void print ()

Console.WriteLine( number1= + number1);


Console.WriteLine( number2= + number2);
Console.ReadLine();

} }

Public static void Main()

Calculator calc = new Calculator (15, -20);


calc = -calc;
calc.Print(); }}
b) How does C# supports inheritance?
Ans: Inheritance is the property by which the objects of a derived class possess
copies of the data members, and the member functions of the base class. C# supp
orts single inheritance.
C# classes support inheritance by using the

operator.

Consider the following example it shows a class B that derives from A. The class
B inherits A s F method, and introduces a G method of its own.

using System;
class A

public void F() {


Console.WriteLine( Inside A.F ); } }

class B: A {
class Test

public void G() { Console.WriteLine( Inside B.G ); } }


{

public static void Main() {


b.F();
b.G();
A a = b;
a.F();

B b = new B();

// Inherited from A
// Introduced in B
// Treat a B as an A

15. Explain different types of arrays present in C# with an example.


Ans: An array is a data structure that contains a number of variables called the
element of the array.
Following types of arrays present in C#:- i) Single dimensional array:- A list o
f items can be given one variable name using one subscript and such a variable c
alled single dimensional array.
ii) Multi dimensional array:- When array variables store a list of value then it
is said to be a multi dimensional array.
iii) Jagged array:- This is an array whose elements are arrays. The element of a
jagged array can be of different dimension and size. It is also called an array
of array . Ex: It shows the declaration of single dimensional array and its initia
lizing in jagged array:int [] [] myJaggedArray = new int[3][];
Initializing:
myJaggedArray[0] = new int[5];
myJaggedArray[1] = new int[4];
myJaggedArray[2] = new int[3];
iv) Passing arrays using ref and out: An out parameters of array type must be assi
gned before it is used in a program. it must be assigned by the calle.
Ex: public static void MyMethod(out int[] arr){
arr= new int [10]; // definite assignment of arr
}
A ref parameter of array type must be definitely assigned by the caller. So, the
re is no need to be definitely assigned by the callee. A ref parameter of an arr
ay type may be altered as a result of the call. The array can be assigned the nu
ll value or can be initialized to a different array.
Ex: public static void MyMethod (ref int[] arr){
arr = new int[10]; }
16. What is data provider? Explain.
Ans: Data Provider:- A data provider is used for connecting to a database, execu
ting commands, and retrieving information. A data provider is designed to be lig
htweight, creating a minimal layer between the data source and application code,
increasing performance without sacrificing functionality. Main component object
s of data provider are:-

i) Connection:- It establishes a connection to a specified data source.


ii) Command:- It executes a command against a data source.
iii) DataReader:- It reads a forward-only, read-only stream of data from a data
source.
iv) DataAdapter:- It populates a DataSet and resolves updates with the data sour
ce.
18. Explain in detail ADO.NET architecture.
Ans: ADO (ActiveX Data Object).NET is a set of classes that provide data access
to the .Net programmer. It has a rich set of components for creating distributed
, data-sharing applications..
The ADO.Net components have designed fr easy data access and manipulation.
There are two central components of ADO.Net:- a) DataSet:- It is the core compo
nents of the disconnected environment of ADO.NET. It is explicitly designed for
data access independent of any data source. It can be used with multiple and dif
ferent data sources, used with XML data, or used to manage data local to the app
lication. It contains a collection of one or more data table objects as well as
primary key, foreign key, constrain, and relation information about the data.
b) Data Provider:- It is the also a other core element of ADO.NET. Its componen
ts (Connection, Command, DataReader, and DataAdapter) are explicitly designed fo
r data manipulation and forward-only, read-only access to data.
Command object enables access to database commands to return data, modify data,
run stored procedure.
Connection object provides connectivity to a data source.
DataReader provides a high performance stream of data from the data source.
DataAdapter provides the bridge between the DataSet object and the data source.
19. Write a program to display

Welcome to ASP.NET

8 times in increasing order

of their font size using ASP.NET.


Ans: The following program displays Welcome to ASP.NET eight times in increasing o
rder of their font size.
In the following code, the Web application name Webapps is application specific:

WebForm1

Welcome to ASP.NET ASHISH

</html>
b) What is the role of system web?
Ans: The System.Web is a namespace that supplies classes and interfaces that ena
bles browser and server communication. This namespace includes the HttpRequest c
lass which provides extensive information about the current HTTP request, the Ht
tpResponse class which manages HTTP output to the client, and the HttpServerUtil
ity class which provides access to server-side utilities and processes. The Syst
em.Web also includes classes for cookies manipulation, file transfer, exception
information, and output cache control.
20. a) Explain the steps or phases involved in implementing .NET remoting applic
ations.
Ans: The phases involved in implementing .NET remoting applications are:
i) Create a remotable object: A remotable object is an object that inherits from
other system object. In .NET remoting, remote objects are accessed through chan
nels. Channels physically transport the messages to and from remote objects.
ii) Create a server to expose the remote object: A server object acts as a liste
ner to accept remote object requests. For this we first create an instance of th
e channel and then we have to register it for use by clients at a specific port.
iii) Create a client to use the remote object: A client object will connect to t
he server, create an instance of the object using the server, and then execute t
he remote methods.
iv) Test the Remoting sample : In this phase, code is tested. After the executin
g of code the client window will then closed while the server remain open and av
ailable.
b) Explain remoting architecture.
Ans: The remoting architecture consists of the remote component, server, client,
and a channel (transportation medium).
i) The remote component is the object that provides services to the client. The
remoting system uses proxy objects to create the impression that the server obje
ct is in the client s process. Proxies are stand-in objects that present themselve
s as some other object. When the client creates a remote instance, the remoting
infrastructure creates a proxy object that looks to our client exactly like the
remote type.
ii) The server creates and register a channel, which is a transportation medium,
to listen at a specified port. The server also registers the remote object.
iii) A channel is a transportation medium through which communication between a

server and a client takes place. It takes a stream of data, creates a package ac
cording to a particular network protocol, and sends the package to another compu
ter.
iv) The client requests for the services of a remote object. A client can choose
the registered channels on the server to communicate with the remote object.
21. Write a program to C# to add two matrices .
Ans:
22. Write a program in C# to check a given string is palindrome or not.
Ans:
22.b)Explain different string functions supported by C#?
Ans: Followings string methods are supported by C#:i)Compare ():- It is used to compare two strings. ii) CompareTo ():- it compares
the current instance with another instance. iii) ConCat ():- It concatenates tw
o or more strings. iv) Copy ():- It creates a new string by copying another. v)
EndsWith ():- It determines whether a substring exists at the of the string. vi)
Equals ():- It determines if two strings are equals. vii) IndexOf ():- It retur
ns the position of the first occurrence of a substring. viii) Insert ():- It ret
urns a new string with a substring inserted at a specified location. ix) Split (
):- It creates an array of strings by splitting the string at any occurrence of
one or more characters. x) StartWith ():- It determines whether a substring exis
ts at the beginning of the string.
23. Define the following:
i) CLR: It stands for Common Language Runtime. CLR is
a runtime environment in which programs written in C# and other .NET languages a
re executed. It provides services such as: Loading and executing of programs, Me
mory isolation for application, Managing exceptions and errors, providing metada
ta, and verification of type safety etc. CLR supports cross-language interoperab
ility. Some components of CLR are: Common Type System, Intermediate Language, Ga
rbage collection, Class loader, and Memory layout.
ii) CTS: It stands for Common Type System. It defines how types are declared, u
sed, and managed in the runtime. Its main functions are:
i) Establishing a commo
n framework that enables cross language integration, type safety, and high perfo
rmance code execution. ii) Providing an object-oriented model. iii) Defining rul
es that languages must follows, so that different languages can interact with ea
ch other.
iii) CLS: It stands for Common Language Specification. It defines a set of rules
that enables interoperability on the .NET platform. These rules serve as a guid
e to third party compiler designers and library builder. The CLS is a subset of
CTS means all the rules that apply to the CTS also apply to the CLS.
24. Mention the important features of C#.
Ans: Important feature of C#: i) It is a simple and consistent programming langua
ge. C# supports a unified type system which eliminates the problem of varying ra
nge of integer types. All types are treated as object so developer extends the t
ype system simply and easily.
ii) It is a modern language because it supports automatic garbage collection, r
obust security model, modern approach to debugging etc.

iii) C# supports all three tenets (Encapsulation, Inheritance, and Polymorphism)


of object- orientation.
iv) C# supports type safety because; it does not permit unsafe code, and all dyn
amically allocated objects and arrays are initialized to zero.
v) C# provides support for versioning with the help of new and override keywords
. Through this feature new software works with existing application easily.
vi) C# supports interoperability and platform independency because it is compat
ible with COM and .NET framework services through tight .NET Base Class Library.
24.b) What is IIS server? Why it is used?
Ans:
25. What is the role of the following :
i) System. Object: System.Object class is the ultimate base class that all types
directly or indirectly drive from. The object class allows us to build generic
routines, which provides Type System Unification, and enables working with group
s collections.
Reference types inherit the object class through other reference types while Val
ue types inherit from System.ValueType, which inherits from System.Object. The o
bject class also allow of using any type in a collection. It contains methods su
ch as Equals, GetType, GetHashCode, MemberwiseClone and Finalize methods that ca
n be reused or overridden in base types.
ii) System. Collection: The System. Collections namespace contain s interfaces a
nd classes that define various collections of objects, such as lists, queues, bi
t arrays, hash tables, and dictionaries. Each class has a set of methods and pro
perties, which are used on those corresponding class objects.
Following are some classes of System.Collection namespace:
i)ArrayList:
The IList interface used in which array whose size is dynamically i
ncreased as required.
ii)BitArray:
Booleans.

It manages a compact array of bit values, which are represented as

iii)CollectionBase:
lection.

It provides the abstract base class for a strongly typed col

iv)DictionaryBase: It provides the abstract base class for a strongly typed coll
ection of key-and-value pairs.
v)Hashtable: It represents a collection of key-and-value pair that are organized
based on the hash code of the key.
iii) System. String: System.String is a buit-in type provided by .NET framework.
When a string is created every times System.String object is instantiated. Stri
ng data type is an alias to the System.String type. Along with the instance memb
er, the System.String class has a few important static methods. These methods do
not require a string instance to work. Some of the methods of this class are:Compare(), CompareTo(), Copy(), Insert() etc.
iv) System. Drawing

26. With the help of an example explain the following:


i) Jagged arrays: A jagged array is an array whose elements are arrays. The elem
ents of jagged array can be of different dimensions and sizes. A jagged array is
also called an array-of-arrays . Jagged array must be initialized before use in pr
ogram.
Ex : using System;
pubic class JaggedArray{
public static void Main(){
// declaring the jagged array of two elements:
int [][] myArray =new int[2][];
// initializing the element:
myArray[0] = new int[5] {1,3,5,7,9};
myArray[1] = new int[4] {2,4,6,8};
// display the array element:
For (int i=0; i
Console.Write( Element is({0}) ,i++);
For (int j=0; j
Console.Write( {0}{1} ,myArray[i][j],j==(myArray[i].Length-1) ?

);

Console.WritelLine();
}}}
ii) Passing arrays using ref and out:
Ans: An out parameters of array type must be assigned before it is used in a pro
gram. it must be assigned by the calle.
Ex: public static void MyMethod(out int[] arr){
arr= new int [10]; // definite assignment of arr }
A ref parameter of array type must be definitely assigned by the caller. So, the
re is no need to be definitely assigned by the callee. A ref parameter of an arr
ay type may be altered as a result of the call. The array can be assigned the nu
ll value or can be initialized to a different array.
Ex: public static void MyMethod (ref int[] arr){
arr = new int[10]; }
27. What are events? Give an example to demonstrate its usage.
Ans: An event is a set of actions that is triggered to call a function or to sta

rt an operation. A class defines an event by providing an event declaration and


an optional set of event assessors. The declaration resembles a field declaratio
n, with an added event keyword. The type of this declaration must be a delegate
type.
Consider the following example:
public static void Button1_Click (object sender, EventArgs e)
{
MessageBox.Show ( Button1 was clicked! );
}
In the above example, a click event is raised when Button1 is clicked.
6) a) What is threading ? List the advantages of using threading.
Ans: Threading: Threads are the basic unit to which an operating system allocate
s processor time, and more than one thread can run inside that process. The proc
ess of developing a program using a thread is called threading.
Advantages of thread: i) It provides communication over a network, to a web serv
er and to a database.
ii) It performs operations that take a large amount of time.
iii) It distinguishes the task on the basis of priority. Ex- a high-priority thr
ead manages time-critical task and a low priority thread performs other task.
iv) It allows the user interface to remain responsive, while allocating time to
background tasks.
b) What are interfaces? Explain the use of interfaces with the help of an exampl
e?
Ans: Interface:- Interface is used to define a class or struct that implements t
he interface. Interface contains methods, properties, indexers, and events as me
mbers. The interface keyword declares a reference type that has an abstract memb
er. They do not contain any private data member and any type of static member. A
ll the members of an interface are public.
Example: Implementation of interface

using System;
interface Addition {
int Add();

interface Multiplication {
int mul ();

class Computation : Addition, Multiplication


Int x, y;

public Computation (int x, int y)

this.x = x;
this .y =y;

public int Add ()

return (x+y);
public int Mul () {
return (x * y);
class test

}}

public static void Main ()

Computation com = new Computation (10, 20);


Addition add = (Addtion) com;
Console.WriteLine ( sum =

+ add.Add ());

Multiplication mul= new (Multiplication)com;


Console.WriteLine ( product =

+ mul.Mul ());

}}

8) Write short notes on:


i) Data Provider: Data Provider:- A data provider is used for connecting to a da
tabase, executing commands, and retrieving information. A data provider is desig
ned to be lightweight, creating a minimal layer between the data source and appl
ication code, increasing performance without sacrificing functionality. Main com
ponent objects of data provider are:i) Connection:- It establishes a connection to a specified data source.
ii) Command:- It executes a command against a data source.
iii) DataReader:- It reads a forward-only, read-only stream of data from a data
source.
iv) DataAdapter:- It populates a DataSet and resolves updates with the data sour
ce.
ii) XML: XML (Extensible Markup Language) is a text based markup language that ena
bles you to store data in a structured format by using meaningful tags. The term
extensible implies that you can extend your ability to describe a document by def
ining meaningful tags for your application. XML is a cross-platform, hardware an
d software independent language. It enables computers to transfer data between h
eterogeneous systems. It is used as a common data interchange format in a number
of applications. Some components of XML are: Processing Instruction, Tags, Elem
ents, Contents, Attributes, Entities, and Comments.

7. Explain the following:


a) Automatic garbage collection
Ans: The garbage collector frees the application from the responsibility of free
ing memory when no longer required. If sufficient memory is not available on the
heap, then the garbage collection process is invoked. The garbage collection pr
ocess begins after the JIT compilation and manages the allocation and deallocati
on of memory for an application. CLR calls garbage collector to handle memory ef
ficiently.
b) Structs
Ans:
c) Working of foreach looping statement
Ans: The foreach statement is similar to for loop, but its implementation is dif
ferent from for loop. foreach enables programmer to iterate the elements in arra
ys and collection classes such as List and HashTable.

Example:- using System;


class test

public static void Main()

int [] arrayInt = {1, 2, 3, 4};


foreach ( int m in arrayInt)

Console .Write(

+ m);

Console.WriteLine (

);

d)Unsafe code
Ans: Unsafe code refers to the code that is processed with low security levels.
There are situations where access to pointer types becomes a necessity. To addre
ss this need, C# provides the ability to write unsafe code. In unsafe code, it i
s possible to declare and operate on pointers, to perform conversions between po
inters and integral types, to take the address of variables, and so forth. In a
sense, it is like writing C code within a C# program. Unsafe code must be clearl
y marked with the modifier unsafe, so developers cannot possibly use unsafe feat
ures accidentally. When CLR finds this unsafe modifier, the execution engine wor
ks to ensure that the unsafe code cannot be executed in an untrusted environment
. The unsafe features are only available in unsafe context.
b) Static constructors
Ans: A static constructor is a member that implements the actions required to in
itialize a class. Static constructors cannot have parameters, they cannot have a
ccessibility modifiers, and they cannot be called explicitly. The static constru
ctor for a class is called automatically.
Example:

class Employee
{
private static DataSet ds;
static Employee()
{
ds = new DataSet( );
}
public string Name;
public decimal Salary;
}

f) Delegates
Ans: Delegates are objects that are used to call the methods of other objects. D
elegates are said to be object-oriented function pointers since they allow a fun
ction to be invoked indirectly by using a reference to the function. A delegate
declaration defines a class that is derived from the class System. Delegate. A d
elegate instance encapsulates one or more methods, each of which is referred to
as a callable entity. For instance methods, a callable entity consists of an ins
tance and a method on that instance. For static methods, a callable entity consi
sts of just a method. Example:

class Test {
static void F()

System.Console.WriteLine( Test.F );

public static void Main()


{
SimpleDelegate dele = new SimpleDelegate(F);
dele();
} }

c) JIT compiler
Ans:

d) Abstract class
Ans:
Destructor
Ans:A destructor is a member that implements the actions required to destroy an
instance of a class. Destructors cannot have parameters, they cannot have access
ibility modifiers, and they cannot be called explicitly. The destructor of an in
stance is called automatically during garbage collection. Example:
using System;
class Point {
public double x, y;
public Point(double x, double y){
this.x = x;
this.y = y;

~Point() {
Console.WriteLine( Destructed {0} , this) }
public override string ToString()

return string.Format( ({0}, {1}) , x, y);


} }

The above example shows a Point class with a destructor.


17. Write a program to show the demonstration of ADO.NET?
A7) a) Explain ASP.NET architecture.
Ans:
11. Explain the method for passing argument in C#.
Ans:
ns ii) Inheritence
BASICS OF .NET
2. What is Meta data?
Ans:- The .NET framework makes language interoperation easier by allowing compil
er to put additional information into all compiled modules and assemblies. This
information is called Meta data. Metadata is binary information describing the p
rogram.

6. What is data provider?


Ans: A data provider is used for connecting to a database, executing commands, a
nd retrieving information. A data provider is designed to be lightweight, creati
ng a minimal layer between the data source and application code, increasing perf
ormance without sacrificing functionality. Main component objects of data provid
er are:- connection, command, DataReader, and DataAdapter.
7. What is exception?
Ans: An exception is any error condition or unexpected behavior encountered
program in execution. Exception can be raised because of fault in our code
hared library or when operating system resources not being available and so
Exception can be handled by using try block. In .NET exception is an object
rits from the ExceptionClass class.

by a
or s
on.
inhe

8. What is backward compatibility?


Ans:- Backward compatibility is the strength of the Windows. It has one disadvan
tage. Whenever the new technology is introduced, the new sets of features are ad
ded to the Window API and its make the code and the design much more complex.
9. What is the use of attributes in C# program?
Ans: Attribute is declarative tag that is used to convey information to runtime
about the behavior of programmatic element such as classes, enumeration and asse
mblies. Attributes are used for adding metadata. Attributes are applied to diffe
rent element of the code. Attributes might require one or more parameter.
10. What is boxing and unboxing? Explain with an example.
Ans: Boxing:- The process of conversion of value type on the stack into object t
ype on the heap is called boxing. Ex: int m= 100;
object om = m;
Unboxing:- The conversion of object type on the heap back into value type on the
stack is called unboxing. Ex: int m=100;
Object om = m;
Int n = (int) om;
11. Explain uses of system collections class.
Ans: The System. Collections namespace contain s interfaces and classes that def
ine various collections of objects, such as lists, queues, bit arrays, hash tabl
es, and dictionaries. Each class has a set of methods and properties, which are
used on those corresponding class objects. Some namespace which are used are: Ar
rayList, BitArray, Comperer, DictionaryBase.
12. What is ASP.NET?
Ans: ASP.NET is a next generation ASP (Active Server Page). It is an entirely ne
w paradigm for server-side ASP scripting. ASP.NET is a unified Web development p
latform that provides the services necessary for us to build enterprise Web appl
ication. It provides new programming model and infrastructure. It has been desig
ned to work seamlessly with what you see Is what you get (WYSIWYG). Its syntax i
s very similar to ASP.

14. How the windows programming is different from. NET Programming?


Ans: Window Programming: In window programming the application programs call win
dows API functional directly. The application run in the windows environment mea
ns operating system. This type of application is called unmanaged or unsafe appl
ications.
.NET Programming: In this programming the application program calls .Net Base Cl
ass library function that will communicate with operating system. The applicatio
n run in .Net Runtime environment. This type of application is called safe appli
cation.
15. What is the importance of automatic memory management? Explain with example.
Ans: Automatic memory management increases the quality and enhances developer pr
oductivity without negative impact on either expressiveness or performance. It p
reserve the time of developer. Ex:

using System;
public class Stack {
private Node first = null;
public bool Empty {
get {
return (first == null);
} }
public object Pop()

if (first == null)
Console.Write( Can t Pop from an empty Stack. );
else {
object temp = first.Value;
first = first.Next;
return temp;
} }
public void Push(object o) {
first = new Node(o, first);
class Node

public Node Next;

public object Value;


public Node(object value):
this(value, null) {}
public Node(object value, Node next) {
Next = next;
Value = value;
}

} }

In the above example, a Stack class is implemented as a linked list of Node inst
ances. These node instances are created in the Push method and are deallocated w
hen no longer in use.

21. With the help of an example differentiate struct and class.


Ans: Structs are similar to classes. But they are different in some ways:
i)Struct are value type while classes are reference type.
ii) A variable of struct type directly contains the data of the struct whereas a
variable of a class type contains a reference to the object.
iii) Struct is useful for small data structure while classes are useful for both
small and large data structure.

You might also like