Sei sulla pagina 1di 5

Solved Assignments for B.Sc.

(IT) BSIT - 61 TA Basics of


.NET
Qus 1) What does .NET framework comprised off?

ANS: The .NET Framework is Microsoft's platform for building applications that have visually stunning user
experiences, seamless and secure communication and the ability to model a range of business processes. The
.NET Framework consists of :

Common Language Runtime - provides an abstraction layer over the operating system.

Base Class Libraries - pre-built code for common low-level programming tasks Development frameworks and
technologies - reusable, customizable solutions for larger programming tasks.

Qus 2)Which are the platform technologies supported by .NET framework?


ANS: The platform technologies mainly supported by .NET framework are ADO.NET, internet technologies and
interface designing.
Qus 3) How the windows programming is different from .NET programming?

ANS: In windows programming the application program calls the windows API function directly. The application
runs on the windows environment ie operating system itself. These type of application are called unmanaged or
unsafe application. In .NET programming the application program call .NET Base Class Library function which will
communicate with the operating system. The application runs in .NET Runtime environment. These type of
application are called managed or safe application. The .net Runtime starts code execution, manages thread,
provides services, managesmemory etc. The .NET Base Classes are fully object oriented. It provides all the
functionalities of traditional windows API along with functionalities in new areas like accessing database, internet
connection and web services.

Qus 4)What is the function of CTS? Explain the classification of types in CTS with a diagram.??
ANS: The Common Type Specification (CTS) performs the following functions:Establishes a common framework
that enables cross language integration, type safety and high performance code execution.Provides an objectoriented model.defines rules that a language must follow, so that different language can interact with other
language.The classification for types of CTS

Qus 5)What are assemblies? What are static and dynamic assemblies?

ANS: Assemblies are the building blocks of .NET Framework applications; they form the fundamental unit of
deployment, version control, reuse, activation scoping, and security permissions. An assembly is a collection of
types and resources that are built to work together and form a logical unit of functionality. An assembly provides
the common language runtime with the information it needs to be aware of type implementations. To the runtime, at
type does not exist outside the context of an assembly.

Static assemblies can include .NET Framework types(interfaces and classes), as well as resources for the
assembly (bitmaps, JPEG files, resource files, and so on). Static assemblies are stored on disk in PE files. You can
also use the .NET Framework to create dynamic assemblies,which are run directly from memory and are not saved
to disk before execution. You can save dynamic assemblies to disk after they have executed.

Qus 6)Explain general structure of c#?

ANS: C# programs can consist of one or more files. Each file can contain one 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 skeleton of a C# program.

using System;
namespace MyNamespace1
{
class MyClass1
{
}struct MyStruct
{
}
interface IMyInterface
{
}delegate int MyDelegate();
enum MyEnum
{
}
namespace MyNamespace2
{
}
class MyClass2
{
public static void Main(string[] args)
{
}
}
}
Qus 7)How do namespaces and types in c# have unique names? Give examples.

ANS: Namespaces are C# program elements designed to help you organize your programs. They also provide
assistance in avoiding name clashes between two sets of code. Implementing Namespaces in your own code is a
good habit because it is likely to save you from problems later when you want to reuse some of your code. For
example, if you created a class named Console, you would need to put it in your own namespace to ensure that
there wasn't any confusion about when the System. Console class should be used or when your class should be
used. Generally, it would be a bad idea to create a class named Console, but in many cases your classes will be
named the same as classes in either the .NET Framework Class Library or a third party library and namespaces
help you avoid the problems that identical class names would cause. Namespaces don't correspond to file or

directory names. If naming directories and files to correspond to namespaces helps you organize your code, then
you may do so, but it is not required. For exp-mynamespace1, mynamspace2 etc.
Qus 8)What is delegate? What is the use of it? Give example.

ANS: A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like
that method. The delegate method can be used like any other method, with parameters and a return value.A
delegate is extremely important for C# as it is one of the four entities that can be placed in a namespace. This
makes it shareable among classes. Delegates are fully object oriented as they entirely enclosed or encapsulate an
object instance and a method. A delegate defines a class and extends System. Delegate. It can call any function as
long as the
methods signature matches the delegates. This makes delegates ideal for anonymous invocation. The methods
signature only includes the return type and the parameter list. If two delegates have the same parameter and return
type, that is, they share the same signature; we consider them as different delegates Public delegate int Perform
Calculation (int x, int y);
Qus 9) Write a program to demonstrate use of enums in C#?

ANS:
=== Example program that uses enums (C#) ===
Using System;
Class Program
{
Enum Importance
{
None,
Trivial,
Regular,
Important,
Critical
};
static void Main()
{
// 1.Importance i1 = Importance. Critical;
// 2.
If (i1 == Importance. Trivial)
{

Console.WriteLine("Not true");
}
Else if (i1 == Importance. Critical)
{
Console.WriteLine ("True");
}
}
}Output of the program True

Qus 10)What is the use of attributes in C# programs?


ANS:
The advantage of using attributes resides in the fact that the information that it contains is inserted into the
assembly. This information can then be consumed at various times for all sorts of purposes:

An attribute can be consumed by the compiler. The System.ObsoleteAttribute attribute that we have just
described is a good example of how an attribute is used by the compiler; certain standard attributes which are only
destined for the compiler are not stored in the assembly. For example, the Serialization Attribute Attribute does not
directly mark a type but rather tells the compiler that type can be serialized. Consequently, the compiler sets certain
flags on the concerned type which will be consumed by the CLR during execution such attributes are also named
pseudo-attributes.
An attribute can be consumed by the CLR during execution. For Example the .NET Framework offers the
System.ThreadStaticAttribute attribute. When a static field is marked with this attribute the CLR makes sure that
during the execution, there is only one version of this field per thread.
An attribute can be consumed by a debugger during execution. Hence,the
System.Diagnostics.DebuggerDisplayAttribute attribute allows personalizing the display of an element of the code
(the state of an object for example) during debugging.
An attribute can be consumed by a tool, for example, the .NET framework offers the
System.Runtime.InteropServices.ComVisibleAttribute attribute. When A class is marked with this attribute, the
tlbexp.exe tool generates a file which will allow this class to be consumed as if it was a COM object.
An attribute can be consumed by your own code during execution by using the reflection mechanism to access
the information. For Example, it can be interesting to use such attributes to validate the value of fields in your
classes. Such a field must be within a certain range. Another reference field must not be null. A string field can beat
most 100 characters. Because of the reflection mechanism, it is easy to write code to validate the state of any
marked fields. A little later, we will show you such an example where you can consume attributes by your own
code.
An attribute can be consumed by a user which analyses an assembly with a tool such as ildasm.exe or Reflector.
Hence you could imagine an attribute which would associate a character string to an element of your code. This
string being contained in the assembly, it is then possible to consult these comments without needing to access
source code.

Potrebbero piacerti anche