Professional Documents
Culture Documents
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.
using System;
class str
Lean ;
string s2 = s1.Insert ( 3,
r );
er );
Console.Write(s3[i]);
Console.WriteLine();
}}
using System;
class CityGuide {
public static void Main() {
Console.WriteLine(
Console.WriteLine( London );
Console.WriteLine( Bombay );
Console.WriteLine( Paris );
Console.WriteLine(
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
[]
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.
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);
T);
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?
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; }}
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
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
(Calculator c1) {
c1.number1 = -c1.number1;
c1.number2 = -c1.number2;
return c1;
} }
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
class B: A {
class Test
B b = new B();
// Inherited from A
// Introduced in B
// Treat a B as an A
Welcome to ASP.NET
WebForm1
</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)CollectionBase:
lection.
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
);
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
using System;
interface Addition {
int Add();
interface Multiplication {
int mul ();
this.x = x;
this .y =y;
return (x+y);
public int Mul () {
return (x * y);
class test
}}
+ add.Add ());
+ mul.Mul ());
}}
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 );
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()
by a
or s
on.
inhe
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
} }
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.