You are on page 1of 20

Short Answer Question

1. What are the uses of the “attributes” in .NET


programming?
Essentially attributes are a means of decorating your code with
various properties at compile time.
This attribute is used at compile time to ensure that attributes can
only be used where the attribute author allows. This attribute also
allows the author to specify whether the same attribute can be
applied multiple times to the same object and if the attribute
applies to objects that derive from the class it is applied to.

2. What is “Well Formatted XML documents”?

XML stands for eXtensible Markup Language.

XML is designed to transport and store data.

XML is important to know, and very easy to learn.

XML document Example

<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

3. What are the benefits of the Metadata?


Metadata serves numerous important purposes such as data
browsing, data transfer, and data documentation.
Here are some additional benefits to think about:
-Metadata helps users answer questions about the data.
- Metadata helps publicize and support the data you or your
organization have produced.
- Metadata supports the creation of a data inventory. Documenting
data and its availability provides agencies with the means to
measure production.
- Metadata may be considered insurance. Having metadata
available insures that potential data users can make an informed
decision about the appropriate use of a data set.
- Metadata is a key component of data lineage. It provides basic
information about the source and derivation of a data set.

4. What is the difference between value type and reference


type?

Value Types : A value type is either a struct type or an enumeration


type.A variable of a value type always contains a value of that
type.Value types are stored on the stack. Assignment to a variable
of a value type creates a copy of the value being assigned. C#
provides a set of predefined struct types called the simple types.
Examples of simple types include

a. int
b. double
c. float
d. boolean
e. Enumerated Data Types(Enums) . We will discuss about
enums and structs in our later article.
f. Struct types etc...

Reference Types : Reference types store references to objects.


Reference types include class types, interface types, delegate
types, and array types.

5. Explain the rules of XML.


-The syntax rules of XML are very simple and logical. The rules are
easy to learn, and easy to use
-XML tags are case sensitive. The tag <Letter> is different from the
tag <letter>.
-Opening and closing tags must be written with the same case.
-In XML, all elements must be properly nested within each other.
-XML documents must contain one element that is the parent of all
other elements. This element is called the root element.
-XML elements can have attributes in name/value pairs just like in
HTML.
-In XML, the attribute values must always be quoted.

6. Write a short note on static page web application.


A static web page shows the required information to the viewer, but
do not accept any information from the viewer. Static pages are
already established and are not drawn up from bits and pieces from
a search query. Until recently search engines could not surf
dynamic pages and thus items on such sites were not listed in
search engines but today some search engines, like Google and
Yahoo, are able to do so. However it takes longer for them to index
all the data especially when there are thousands of products and if
you have set up products with similar descriptions it can cause
duplicate content issues.

7. What are the private assemblies?

Private Assemblies

Intended use by single applications. Building modules to group common


functionality.

• Location is specified at compile time. Usually in the same folder like


the application's EXE file or in any of the sub folders.

• PATH is not checked while looking up files, neither set by Control Panel
'System' configuration nor set in a Console Window.

• Identified by name and version if required. But only one version at a


time.

• Digital signature possible to ensure that it can't be tampered.

• Get smaller EXE files.

• Dynamic linking, i.e. loading on demand.

8. What is garbage collection?


The garbage collector in .Net takes care of bulk of the memory
management responsibility, freeing up the developer to focus on
core issues. The garbage collector is optimized to perform the
memory free-up at the best time based upon the allocations being
made. Java developers have enjoyed the benefits of Garbage
collection. VB developers are also used to a certain amount of
flexibility in these terms and .Net provides full-fledged memory
management capabilities for managed resources.

9. Write a short note on assembly manifest.


The manifest describes the assembly itself, providing the logical
attributes shared by all the modules and all components in the
assembly. The manifest contains the assembly name, version
number, locale and an optional strong name that uniquely
identifying the assembly. This manifest information is used by the
CLR. The manifest also contains the security demands to verify this
assembly. It also contains the names and hashes of all the files that
make up the assembly. The .NET assembly manifest contains a
cryptographic hash of different modules in the assembly. And when
the assembly is loaded, the CLR recalculates the hash of the
modules at hand, and compares it with the embeded hash. If the
hash generated at runtime is different from that found in the
manifest, .NET refuses to load the assembly and throws an
exception.

10. What is Containment/Delegation Model?

11. What is the difference between abstract class and


interface?
Interfaces provide a form of multiple inheritance. A class can extend
only one other class.
Interfaces are limited to public methods and constants with no
implementation. Abstract classes can have a partial implementation,
protected parts, static methods, etc. A Class may implement several
interfaces. But in case of abstract class, a class may extend only one
abstract class. Interfaces are slow as it requires extra indirection to to find
corresponding method in in the actual class. Abstract classes are fast.

12. What is the use of connection object in ADO.NET?


The Connection Object is a part of ADO.NET Data Provider and it is a
unique session with the Data Source. In .Net Framework the
Connection Object is Handling the part of physical communication
between the application and the Data Source. Depends on the
parameter specified in the Connection String , ADO.NET Connection
Object connect to the specified Database and open a connection
between the application and the Database . When the connection is
established , SQL Commands may be executed, with the help of the
Connection Object, to retrieve or manipulate data in the Database.
Once the Database activity is over , Connection should be closed
and release the resources .

The ADO Connection Object is used to create an open connection to


a data source. Through this connection, you can access and
manipulate a database.

If you want to access a database multiple times, you should


establish a connection using the Connection object. You can also
make a connection to a database by passing a connection string via
a Command or Recordset object. However, this type of connection is
only good for one specific, single query.

13. What is the element and attribute in XML?

ML Element

XML is a markup language that is used to store data in a self-explanatory


manner. Making the data "self-explanatory" comes about by containing
information in elements. If a piece of text is a title then it will be contained
within a "title" element.

XML Attribute

Attributes are used to specify additional information about the element. It


may help to think of attributes as a means of specializing generic elements
to fit your needs. An attribute for an element appears within the opening tag.

If there are multiple values an attribute may have, then the value of the
attribute must be specified. For example, if a tag had a color attribute then
the value would be: red, blue, green, etc. The syntax for including an
attribute in an element is:

• <element attributeName="value">
In this example we will be using a madeup XML element named "friend" that
has an optional attribute age.

• Elements are used to classify data in an XML document so that the


data becomes "self-explanatory".
• Opening and closing tags represent the start and end of an
element.
• Attributes are used to include additional information on top of the
data that falls between the opening and closing tag.

14. Write a short note on dynamic page web application.


A dynamic web page is a hypertext document rendered to a World
Wide Web user presenting content that has been customized or
actualized for each individual viewing or rendition or that
continually updates information as the page is displayed to the
user.
A web document that is created from a database in real-time or "on
the fly" at the same time it is being viewed, providing a continuous
flow of new information and giving visitors a new experience each
time they visit the web site.
A web page that is composed by a program running on the web server
computer based on factors such as the kind of request from the
browser and what information is currently available. To the browser
it looks exactly like a static page.

Long Answer Question


15. What are the parameter modifiers? Explain each in brief.

Parameter modifiers in C# are entities that controls the behaviour


of the arguments passed in a method. Following are the different
parameter modifiers in C#:
1) None - if there is NO parameter modifier with an argument, it is
passed by value, where the method recieves a copy of the original
data.
2) out - argument is passed by reference. The argument marked
with "out" modifier needs to be assigned a value within this
function, otherwise a compiler error is returned.

public void multiply(int a, int b, out int prod)


{
prod = a * b;
}
Here, note that prod is assigned a value. If not done so, then a
compile time error is returned.
3) params- This modifier gives the permission to set a variable
number of identical datatype arguments.
Note that a method may have only one "params" modifier. The
params modifier needs to be in the last argument.

C# Example
static int totalruns(params int[] runs)
{
int score = 0;
for(int x=0; x
&nsbp;score+=runs[x];
return score;
}

Further, from the calling function, we may pass the scores of each
batsman as below...

score = totalruns(12,36,0,5,83,25,26);

4) ref - The argument is given a value by the caller, where data is


passed by reference. This value may optionally be reset in the
called method. Note that even if NO value is set in the called
method for the ref attribute, no compiler error is raised.

16. Explain in brief the Boxing and Unboxing operations with


examples.

Boxing permits any value type to be implicitly converted to type


object or to any interface type Implemented by value type. It is the
process of allocating an object instance and copying the value type
value into that instance.

E.g.
Int I =10;
A boxing conversion involves copying of the value being boxed.

Boxing permits any value type to be explicitly converted to type


object or to any interface type Implemented by value type. It first
checks the object instance is a boxed value of the given value-type,
and then copying the value out of the instance.

E.g.
Object box = 11;
Int I = (int) box;

17. What is ADO.NET; explain the connected layer of ADO.NET.

ADO.NET stands for ActiveX Data Objects for .NET. It refers to the
suite of data access technologies used to manipulate databases.
ADO.NET is part of the .NET Framework.

ADO.NET is an object-oriented set of libraries that allows you to


interact with data sources. Commonly, the data source is a
database, but it could also be a text file, an Excel spreadsheet, or
an XML file. For the purposes of this tutorial, we will look at
ADO.NET as a way to interact with a data base.

ADO.net means Activex Data Object.

ADO.net provides the activ coonectivity with the database at


runtime. We can do the operations which are related to the
database.

It is a part of the base class library that is included with the


Microsoft .NET Framework. It is commonly used by programmers to
access and modify data stored in relational database systems,
though it can also access data in non-relational sources

18. How to build an application where we pass Interfaces as


parameter to a method and interface as return type for a
method.

19. Explain the basic concept of object lifetime and


generations.
the object lifetime (or life cycle) of an object in object-oriented
programming is the time between an object's creation (also known
as instantiation or construction) till the object is no longer used,
and is destructed or freed.
Example:
namespace ObjectLifeTime
{
class Foo
{
public Foo()
{
// This is the implementation of
// default constructor
}

public Foo(int x)
{
// This is the implementation of
// the one-argument constructor
}
~Foo()
{
// This is the implementation of
// the destructor
}

public Foo(int x, int y)


{
// This is the implementation of
// the two-argument constructor
}

public Foo(Foo old)


{
// This is the implementation of
// the copy constructor
}

public static void main(string[] args)


{
Foo defaultfoo = new Foo(); // call default constructor
Foo foo = new Foo(14); // call first constructor
Foo foo2 = new Foo(12, 16); // call overloaded constructor
Foo foo3 = new Foo(foo); // call the copy constructor

}
}
}
20. Explain the role and format of .Net assemblies.

An assembly is a collection of one or more .exe or dll’s. An assembly is


the fundamental unit for application development and deployment
in the .NET Framework. An assembly contains a collection of types
and resources that are built to work together and form a logical unit
of functionality. An assembly provides the CLR with the information
it needs to be aware of type implementations.

An assembly in ASP.NET is a collection of single-file or multiple files.


The assembly that has more than one file contains either a dynamic
link library (DLL) or an EXE file. The assembly also contains
metadata that is known as assembly manifest. The assembly
manifest contains data about the versioning requirements of the
assembly, author name of the assembly, the security requirements
that the assembly requires to run, and the various files that form
part of the assembly.

Assemblies are main building blocks. An assembly maybe defined as a unit


of deployment. A single assembly is a collection of types, and resources. The
CLR does not understand any types that are outside assemblies. The CLR
executes the code in assemblies as they contain MSIL code. They define
type, version and security boundaries.

Assemblies in .Net are a solution to the Dll hell problem as one can use
different versions of same assembly in different applications at the same
time. To make a shared assembly, we need to register it with GAC where as
private assemblies reside in applications directory.

21. What are the major categories of ASP.NET web controls?


Explain any one of these control.

ASP.NET - Web Server Controls

Web server controls are special ASP.NET tags understood by the server.

Like HTML server controls, Web server controls are also created on the
server and they require a runat="server" attribute to work. However, Web
server controls do not necessarily map to any existing HTML elements and
they may represent more complex elements.

The syntax for creating a Web server control is:

<asp:control_name id="some_id" runat="server" />


In the following example we declare a Button server control in an
.aspx file. Then we create an event handler for the Click event which
changes the text on the button:

<script runat="server">
Sub submit(Source As Object, e As EventArgs)
button1.Text="You clicked me!"
End Sub
</script>

<html>
<body>

<form runat="server">
<asp:Button id="button1" Text="Click me!"
runat="server" OnClick="submit"/>
</form>

</body>
</html>

22. Write a short note on CTS, CLS.


Common Type System (CTS) describes the data types that can be used by
managed code. CTS defines how these types are declared, used and
managed in the runtime. It facilitates cross- language integration, type
safety, and high performance code execution. The rules defined in CTS can
be used to define your own classes and values.
A fundamental part of the .NET Framework's Common Language Runtime
(CLR), the CTS specifies no particular syntax or keywords, but instead
defines a common set of types that can be used with many different
language syntaxes.this is used to communicate with other language.
example in vb we have int and in c++ we have long so that in one case they
are not compatiable with each other so that CTS palys important role with
using System.int32.

Common Language Specification (CLS) defines the rules and


standards to which languages must adhere to in order to be
compatible with other .NET languages. This enables C# developers
to inherit from classes defined in VB.NET or other .NET compatible
languages.

This is a subset of the CTS which all .NET languages are expected to
support. It was always a dream of Microsoft to unite all different
languages in to one umbrella and CLS is one step towards that.
Microsoft has defined CLS which are nothing but guidelines that
language to follow so that it can communicate with other .NET
languages in a seamless manner. It is a set of types that may be
used in external calls in code that is intended to be portable. All of
the standardized framework (described in Partition IV, including the
Base Class Library, XML Library, Network Library, Reflection Library,
and Extended Numerics Library) are intended to be used on any
system running a compliant VES, and in any CLScompliant
language. Therefore, the framework follows the CLS rules, and all
(well, almost all) the types it defines are CLS-compliant to ensure
the broadest possible use. In the few cases in which types or
methods are not CLS-compliant, they are labeled as such (that’s
one of the CLS rules), and they are intended for use by compilers
and language runtimes rather than direct use by programmer

23. What is XML? Explain uses, syntax and declarations of XML.

XML (eXtensible Markup Language) is a meta-language; that is, it is a


language in which other languages are created. In XML, data is
"marked up" with tags, similar to HTML tags. In fact, the latest
version of HTML, called XHTML, is an XML-based language, which
means that XHTML follows the syntax rules of XML.

XML is used to store data or information. This data might be intended


to be by read by people or by machines. It can be highly structured
data such as data typically stored in databases or spreadsheets, or
loosely structured data, such as data stored in letters or manuals.

Initially XML received a lot of excitement, which has now died down
some. This isn't because XML is not as useful, but rather because it
doesn't provide the Wow! factor that other technologies, such as
HTML do. When you write an HTML document, you see a nicely
formatted page in a browser - instant gratification. When you write
an XML document, you see an XML document - not so exciting.
However, with a little more effort, you can make that XML document
sing!

XML has relatively straightforward, but very strict, syntax rules. A


document that follows these syntax rules is said to be well-formed.

1. There must be one and only one document element.


2. Every open tag must be closed.
3. If an element is empty, it still must be closed.
o Poorly-formed: <tag>
o Well-formed: <tag></tag>
o Also well-formed: <tag />
4. Elements must be properly nested.
o Poorly-formed: <a><b></a></b>
o Well-formed: <a><b></b></a>
5. Tag and attribute names are case sensitive.
6. Attribute values must be enclosed in single or double quotes.

Example:

<?xml version="1.0"?>
<person>
<name>
<firstname>Paul</firstname>
<lastname>McCartney</lastname>
</name>
<job>Singer</job>
<gender>Male</gender>
</person>

24. Write a short note on CLR

The Common Language Runtime (CLR) is the environment where all


programs in .NET are run. It provides various services, like memory
management and thread management. Programs that run in the CLR need
not manage memory, as it is completely taken care of by the CLR. For
example, when a program needs a block of memory, CLR provides the block
and releases the block when program is done with the block.

All programs targeted to .NET are converted to MSIL (Microsoft Intermediate


Language). MSIL is the output of language compilers in .NET (see figure 2).
MSIL is then converted to native code by
JIT (Just-in Time Compiler) of the CLR and
then native code is run by CLR.

As every program is ultimately


converted to MSIL in .NET, the
choice of language is pure
personal. A program written in
VB.NET and a program written in
C# are both converted to MSIL.
Then MSIL is converted to native
code and run. So, whether you write program in C# or VB.NET at
the end it is MSIL all that you get.

25. What is the role of .NET Exception Handling? Explain the


difference between System level exception and application level
exception.

26. Write a short note on generic and non-generic collections.

Using generic collections is generally recommended, because you gain the


immediate benefit of type safety without having to derive from a base
collection type and implement type-specific members. In addition, generic
collection types generally perform better than the corresponding nongeneric
collection types (and better than types derived from nongeneric base
collection types) when the collection elements are value types, because with
generics there is no need to box the elements.

The following generic types correspond to existing collection types:

• List is the generic class corresponding to ArrayList.


• Dictionary is the generic class corresponding to Hashtable.
• Collection is the generic class corresponding to CollectionBase.
Collection can be used as a base class, but unlike CollectionBase it
is not abstract, making it much easier to use.
• ReadOnlyCollection is the generic class corresponding to
ReadOnlyCollectionBase. ReadOnlyCollection is not abstract, and has
a constructor that makes it easy to expose an existing List as a read-
only collection.
• The Queue, Stack, and SortedList generic classes correspond to the
respective nongeneric classes with the same names.
• using System;
• namespace HP.Mahesh.GenericsExample.Methods.CSharp
• {
• class GenericsSample
• {
• static void Main(string[] args)
• {
• //Integer parameters against the Swap method

• Int32 a = 10, b = 20;
• System.Console.WriteLine("Value of a, b are {0} and {1}", a,
b);
• Swap<INT32>(ref a, ref b);
• System.Console.WriteLine("Value of a, b " +
• "after swapping are {0} and {1}", a, b);

• //String parameters against the Swap method

• String a1 = "First", a2 = "Second";
• System.Console.WriteLine("Value of strings a1," +
• " a2 are {0} and {1}", a1, a2);
• Swap<STRING>(ref a1, ref a2);
• System.Console.WriteLine("Value of strings a1," +
• " a2 after swapping are {0} and {1}", a1, a2);

• System.Console.ReadLine();
• }//end of the Main Method


• public static void
• Swap<GENERICTYPE>(ref GenericType firstParameter,
• ref GenericType secondParameter)
• {
• GenericType temp;
• temp = firstParameter;
• firstParameter = secondParameter;
• secondParameter = temp;
• }//end of the Swap method

• }
• }

The overview of the non-generic collection interfaces and classes in Figure


47.1 is a counterpart to the sum of Figure 45.1 and Figure 46.1. The white
boxes represent interfaces and the grey boxes represent classes. Most
classes and interfaces shown in Figure 46.1 belong to the namespace
System.Collections.

The non-generic collection classes store data of type


Object

As the most important characteristics, the elements of the lists are of type
Object. Both keys and values of dictionaries are Objects. Without use of type
parametrization, there are no means to constraint the data in collections to
of a more specific type. Thus, if we for instance work with a collection of
bank accounts, we cannot statically guarantee that all elements of the
collection are bank accounts. We may accidentally insert an object of
another type. We will find the error at runtime. Most likely, an exception will
be raised when we try to cast an Object to BankAccount.

27. Write a short note on Stack and Queue in .NET.

Both stacks and queues are like lists (ordered collections of items), but with
more restricted operations. They can both be implemented either using an
array or using a linked list to hold the actual items.

Stacks

The conceptual picture of a stack is something like this:

_______ _________
/ \ / \
values in \/ / \/
| ----- | values out
| |
| ----- |
| |
| ----- |
| |
| |
----------
Think of a stack of newspapers, or trays in a cafeteria. The only item
that can be taken out (or even seen) is the most recently added
item; a stack is a Last-In-First-Out (LIFO) data structure.

Here are the stack operations:

OPERATION DESCRIPTION

Stack() (constructor) create an empty stack

boolean
return true iff the stack is empty
empty()

int size() return the number of items in the stack

void add ob to the top of the stack


push(Object
ob)

remove and return the item from the top of the


Object pop()
stack (error if the stack is empty)

return the item that is on the top of the stack, but


Object peek()
do not remove it (error if the stack is empty)

Queues

The conceptual picture of a queue is something like this:

------------------
values in ----> items in the queue ----> values out
------------------
^ ^
| |
this is the rear of this is the front of
the queue the queue
Think of people standing in line. A queue is a First-In-First-Out (FIFO)
data structure. Items can only be added at the rear of the queue,
and the only item that can be removed is the one at the front of
the queue.

Here are the queue operations:

OPERATION DESCRIPTION

Queue() (constructor) create an empty queue

boolean empty() return true iff the queue is empty

int size() return the number of items in the queue

void
enqueue(Object add ob to the rear of the queue
ob)

remove and return the item from the front of


Object dequeue()
the queue (error if the queue is empty)

28. What is Type Reflection? How custom metadata viewer is


build?

You can use reflection to explore and examine the contents of an assembly.
You can find the types associated with a module; the methods, fields,
properties, and events associated with a type, as well as the signatures of
each of the type's methods; the interfaces supported by the type; and the
type's base class.

To start, load an assembly dynamically with the Assembly.Load static


method. The Assembly class encapsulates the actual assembly itself, for
purposes of reflection. The signature for the Load method is:

public static Assembly.Load(AssemblyName)


Reflecting on an assembly
namespace Programming_CSharp
{
using System;
using System.Reflection;

public class Tester


{
public static void Main( )
{
// what is in the assembly
Assembly a = Assembly.Load("Mscorlib.dll");
Type[] types = a.GetTypes( );
foreach(Type t in types)
{
Console.WriteLine("Type is {0}", t);
}
Console.WriteLine(
"{0} types found", types.Length);
}
}
}

29. Explain in brief – C# Polymorphic Support.

Polymorphism comes from the Greek words of poly and morphos. The literal
translation means "many forms", which in essence is how we use
polymorphism in programming.

The easiest way to think about polymorphism is to use an example. Suppose


that we are creating a piece of software such as a drawing/image package.
As we draw shapes, we want to keep a list of what we add, this way we can
remove them using the undo function. So if we created a collection of
shapes, we could put squares, pentagons, or any of the shapes into the
collection and the behaviour that they respond to is the same for each object
in the collection.

A shape has many forms. Shape is just the generic name for them.

Polymorphism is an Important concept in Object Oriented


Programming. Polymorphism mean “Many Forms” it’s a Greek word.
In computer language Method Overloading is also a kind of
polymorphism where you call one function and it behave differently
according to parameters and it’s return type.

Another thing about Polymorphism is accessing Child class methods


using Base class object let’s see how You can do polymorphism
using C#.
namespace in Program.cs file)

using System;
using System.Collections.Generic;
using System.Text;

namespace C_Sharp_Polymorphism_Tutorial
{
public class Program
{
static void Main(string[] args)
{
Parent[] obj = new Parent[2];
obj[0] = new Parent();
obj[1] = new Child();

for (int i = 0; i < obj.Length; i++)


{
obj[i].PrintName("Irfan");
}

}
}

public class Parent


{
public virtual void PrintName(string name)
{
Console.WriteLine("Parent Class Printing Name");
Console.WriteLine("Name is {0}", name);
}
}
public class Child : Parent
{
public override void PrintName(string name)
{
Console.WriteLine("Child Class Printing Name");
Console.WriteLine("Name is {0}", name);
}
}
}

How C# Polymorphism Works!

• I had created two classes Parent and Child and define a method
PrintName().

• In parent class I make it virtual and in Child class I override it.By


doing this child class has complete control of derived method
PrintName from it’s Parent.

• Then in Static Method I declare Array of Parent class which can hold
two elements in it In First index of Array “obj[0]” I instantiate object
of Parent Class and in Second Instantiate Child Class.

• Now Loop through this array and call PrintName method (Here it is I
am implementing polymorphism Calling child class method from
base class object).

***************** ****************

You might also like