0% found this document useful (0 votes)
409 views11 pages

6th Sem Basic of .Net Kuvempu University

The document discusses the basics of .NET framework. It includes the architecture of .NET framework which has two main components - Common Language Runtime (CLR) and .NET Framework Class Library. CLR provides a runtime environment and handles memory management. The class library contains reusable classes and methods. The document also discusses Common Type System which defines common data types, and Common Language Specification which specifies rules for language compilers targeting CLR.

Uploaded by

mofid khan
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)
409 views11 pages

6th Sem Basic of .Net Kuvempu University

The document discusses the basics of .NET framework. It includes the architecture of .NET framework which has two main components - Common Language Runtime (CLR) and .NET Framework Class Library. CLR provides a runtime environment and handles memory management. The class library contains reusable classes and methods. The document also discusses Common Type System which defines common data types, and Common Language Specification which specifies rules for language compilers targeting CLR.

Uploaded by

mofid khan
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/ 11

www.niitprince.blogspot.

in
BASICS OF .NET

BSIT-61

PART-A
Answer all questions: 25 Marks
1. Mention any four languages integrated with .NET. 2 Marks
Answer: (write any four)
1.
2.
3.
4.
5.
6.
7.
8.

C#
C++
J++
VB.NET
ASP.NET
Scripting Languages
ADO/OLE DB
COM and COM+

2. Mention any four advantages of using .NET

4 Marks

Answer:(write any four)


1.
2.
3.
4.
5.
6.
7.

Consistent Programming Model


Language Independence
No Versioning Problem easy application deployment and maintenance
improved security
support for web services
Dynamic web
visual studio.net

3. What are the three major functionalists of CLR?

3 Marks

Answer:
The main function of Common Language Runtime (CLR) is to convert the Managed Code into
native code and then execute the Program. The Managed Code compiled only when it needed,
that is it converts the appropriate instructions when each function is called . The Common
Language Runtime (CLR) s Just In Time (JIT) compilation converts Intermediate Language
(MSIL) to native code on demand at application run time.

Functions of CLR
1.Convert IL code into Operating System native code
2. Execption handling
3. Type safety

4. Memory management.
5. Security etc.
4. Mention any three preprocessor directories of C#.

3 Marks

Answer:(write any three)


The preprocessors directives give instruction to the compiler to preprocess the information
before actual compilation starts.
List of Preprocessor Directives in C#
The following table lists the preprocessor directives available in C#:
Preprocessor
Directive
#define
#undef
#if
#else
#elif
#endif
#line
#error
#warning
#region
#endregion

Description.
It defines a sequence of characters, called symbol.
It allows you to undefine a symbol.
It allows testing a symbol or symbols to see if they evaluate to true.
It allows to create a compound conditional directive, along with #if.
It allows creating a compound conditional directive.
specifies the end of a conditional directive.
It lets you modify the compilers line number and (optionally) the file name
output for errors and warnings.
It allows generating an error from a specific location in your code.
It allows generating a level one warning from a specific location in your
code.
It lets you specify a block of code that you can expand or collapse when
using the outlining feature of the Visual Studio Code Editor.
It marks the end of a #region block.

5. Mention three advantages of C# .

3 Marks

Answer:

It is compiled to an intermediate language (CIL) indepently of the language it was


developed or the target architecture and operating system
Automatic Garbage collection
Pointer no longer needed (but optional)
Definition of classes and functions can be done in any order.

6. Mention any three kinds of operators in C#.

3 Marks

Answer:
The following table shows a set of operators used in the C# language.

Category
Symbol
+ Sign operators
+ - * / %
Arithmetic
& | ^ ! ~ && || true false
Logical (boolean and bitwise)
+
String concatenation
++ -Increment, decrement
<< >>
Shift
== != < > <= >=
Relational
= += -= *= /= %= &= |= ^= <<= >>=
Assignment
.
Member access
[]
Indexing
()
Cast
?:
Ternary
Delegate concatenation and removal + new
Object creation
as is sizeof typeof
Type information
checked unchecked
Overflow exception control
* -> [] &
Indirection and address
=>
Lambda
7. Mention the four types of iteration statements in C#.

4 Marks

Answer:
Following types of iterative statements are there in C#.
While:
The statement block of while statement is executed while the boolean expression is true. It may
execute zero or more times. If the boolean expression is false initially, the statement block is not
executed.

int i = 9;
int j = 7;
int sum = 0;
while (j < i)
{
sum += j;
j++;
}

Do While:

Do While is almost similar to While statement except it validate its boolean expression after the
statement block. It guranttees that the statement block shall run atleast once for sure. Further
iterations of the statement block continues while the boolean expression is true.

int i = 9;
int j = 10;
int sum = 0;
do
{
sum += j;
j++;
} while (j < i);

For
The For statement iterate a code block until a specified condition is reached similar to while
statement. The only difference of for statement has over while statement is that for statement has
its own built-in syntax for intiliazing, testing, and incrementing/decrementing (3 clauses) the
value of a counter.
The first clause is the initialize clause in which the loop iterators are declared.
The second clause is the boolean expression that must evaluate to a boolean type and the
statement block is repeated until this expression is false.
The third clause is to increment/decrement the value that is executed after each iteration.
All three clauses must be separated by a semicolon (;) and are optional. For statement block is
repeated zero or more times based on the boolean expression validation (second clause).

int j = 10;
int sum = 0;
for (int i = 0; i < j; i++)
{
sum += i;
}

Foreach
ForEach statement is desiged to loop through a similar type of items in a collection. As each
element is enumerated, the identifier is assigned the new element, and the statement block is
repeated. The scope of the identifier is within the foreach statement block. The identifier must be
of the same type extracted from the collection and is read-only.

string[] days = { sunday, monday, tuesday };


string output = string.Empty;

foreach (string s in days)


{
output = string.Concat(output, s + > );
}

8. What is an exception? Given an example.


Answer:

2 Marks

An Exception is any error condition or unexpected behavior encountered by a program in


execution. Exceptions can be raised because of a fault in our code or in shared library or when
operating system is resources is not being able or when unexpected conditions the CLR
encountered and so on.
Example:

using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i, j, divide = 0;
i = 10;
j = 0;
try
{
divide = i / j;
}
catch (DivideByZeroException)
{
divide = 0;
}
finally
{
Console.WriteLine(divide);
}
Console.ReadLine();
}
}
}

9. What does XML stand for?


Answer: extensible markup language.

PART -B

1) a) Draw the architecture of .NET frame work and explain its components . 10 Marks
Answer:

Net Framework is a platform that provides tools and technologies to develop Windows, Web and
Enterprise applications. It mainly contains two components,
1. Common Language Runtime (CLR)
2. .Net Framework Class Library.
1. Common Language Runtime (CLR)
.Net Framework provides runtime environment called Common Language Runtime (CLR).It
provides an environment to run all the .Net Programs. The code which runs under the CLR is
called as Managed Code. Programmers need not to worry on managing the memory if the
programs are running under the CLR as it provides memory management and thread
management.
Programmatically, when our program needs memory, CLR allocates the memory for scope and
de-allocates the memory if the scope is completed.
Language Compilers (e.g. C#, VB.Net, J#) will convert the Code/Program to Microsoft
Intermediate Language (MSIL) intern this will be converted to Native Code by CLR. See the
below Fig.

There are currently over 15 language compilers being built by Microsoft and other companies
also producing the code that will execute under CLR.
2.

.Net Framework Class Library (FCL)

This is also called as Base Class Library and it is common for all types of applications i.e. the
way you access the Library Classes and Methods in VB.NET will be the same in C#, and it is
common for all other languages in .NET.
The following are different types of applications that can make use of .net class library.
1.
2.
3.
4.
5.

Windows Application.
Console Application
Web Application.
XML Web Services.
Windows Services.

In short, developers just need to import the BCL in their language code and use its predefined
methods and properties to implement common and complex functions like reading and writing to
file, graphic rendering, database interaction, and XML document manipulation.
Below are the few more concepts that we need to know and understand as part of this .Net
framework.
3. Common Type System (CTS)
It describes set of data types that can be used in different .Net languages in common. (i.e), CTS
ensures that objects written in different .Net languages can interact with each other.
For Communicating between programs written in any .NET complaint language, the types have
to be compatible on the basic level.
The common type system supports two general categories of types:
Value types:

Value types directly contain their data, and instances of value types are either allocated on the
stack or allocated inline in a structure. Value types can be built-in (implemented by the runtime),
user-defined, or enumerations.
Reference types:
Reference types store a reference to the values memory address, and are allocated on the heap.
Reference types can be self-describing types, pointer types, or interface types. The type of a
reference type can be determined from values of self-describing types. Self-describing types are
further split into arrays and class types. The class types are user-defined classes, boxed value
types, and delegates.
4. Common Language Specification (CLS)
It is a sub set of CTS and it specifies a set of rules that needs to be adhered or satisfied by all
language compilers targeting CLR. It helps in cross language inheritance and cross language
debugging.
Common language specification Rules:
It describes the minimal and complete set of features to produce code that can be hosted by CLR.
It ensures that products of compilers will work properly in .NET environment.
Sample Rules:
1. Representation of text strings
2. Internal representation of enumerations
3. Definition of static members and this is a subset of the CTS which all .NET languages are
expected to support.
4. 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.
b) What do you mean by backward compatibility in .NET? Explain

5 Marks

Ans:
Backward compatibility means that an application developed for a particular version of a
platform will run on later versions of that platform. The .NET Framework tries to maximize
backward compatibility: Source code written for one version of the .NET Framework should
compile on later versions of the .NET Framework, and binaries that run on one version of the
.NET Framework should behave identically on later versions of the .NET Framework.
2) a) Explain the compilation of .NET programming languages.

7 Marks

b) What are assemblies? What are Static &Dynamic assemblies? Explain.


Answer:

8 Marks

Assembly is a basic element of packaging in .NET. An assembly consist of IL code, metadata


that describes what is in the assembly, and any other or information that the application needs to
run, such as graphics and sound files.
Functions of assembly:

It contains code that the CLR executes. Assembly contains IL code plus the manifest in a
portable executable(PE) file will be executed by CLR.
As Assembly is the unit at which permission are requested and granted. hence it forms a
security boundary.
It forms a type boundary. Every assembly has a unique name and the types within those
assemblies includes the name of the assembly. hence every type has unique name or
unique boundary.
The assemblys manifest contains assembly metadata that is used by CLR for resolving
types as satisfying resource requests.

3) a) Write the general structure of C# program.

7 Marks

Ans:
C# programs can consist of one or more files. Each file can contain zero or more namespaces. A
namespace can contain types such as classes, structs, interfaces, enumerations, and delegates, in
addition to other namespaces. The following is the skeleton of a C# program that contains all of
these elements.
A C# program basically consists of the following parts:

Namespace declaration
A class
Class methods
Class attributes
A Main method
Statements & Expressions
Comments
using System;
namespace YourNamespace
{
class YourClass
{
}
struct YourStruct
{
}
interface IYourInterface
{
}
delegate int YourDelegate();

enum YourEnum
{
}
namespace YourNestedNamespace
{
struct YourStruct
{
}
}
class YourMainClass
{
static void Main(string[] args)
{
//Your program starts here...
}
}
}

b) List out differences between C# and C++.

8 Marks

Answer:
C# is a programming language that is derived from C programming
language and C++ programming language. C# is uniquely designed to be
used in .NET platform. The differences between C# and C++ are:
C#
C# is a high level language that is
component oriented.
When compiled, C# code is converted into
Intermediate language
code. This intermediate language code is
converted into executable
code through the process called Just-InTime compilation.
In C#, memory management is
automatically handled by garbage collector.
In C# Switch Statement, the test variable
can be a string.
In C# switch statement, when break
statement is not given, the fall
through will not happen to the next case
statement if the current
case statement has any code.
In addition to for, while and do..while, C#
has another flow control statement called
for each.

C++
C++ is a low level and indeed platform
neutral programming language.
When compiled, C++ code is converted into
assembly language code.

In C++, the memory that is allocated in the


heap dynamically has to be explicitly deleted.
In C++ Switch Statement, the test variable
cannot be a string.
In C++ switch statement, when break
statement is not given, the
fall through will happen to the next case
statement even if the
current case statement has any code.
C++ does not contain for each statement.

C# struts can contain only value types. The


struts is sealed and it cannot have a default
no-argument constructor.
In C#, delegates, events and properties can
also be specified as class members.

In C#, the end of the class definition has a


closing brace alone.
The access modifiers in C# are public,
private, protected, internal and protected
internal.

C++ struts behave like classes except that the


default access is public instead of private.
In C++, only variables, constructors,
functions, operator overloads
and destructors can be class members.
Delegates, events and
properties cannot be specified as class
members.
In C++, the end of the class definition has a
closing brace followed by a semicolon.
The access modifiers in C++ are public,
private, protected. C++
does not have internal and protected internal
access modifiers.
C++ does not have finally block in exception
handling mechanism.

C# has finally block in exception handling


mechanism. The code
statements in the finally block will be
executed once irrespective of
exception occurrence.
The exception in C# can only throw a class The exception in C++ can throw any class.
that is derived from the System.Exception
class.
C# does not have the concept of function
C++ has the concept of function pointers.
pointers. C# has a similar concept called
Delegates.

You might also like