Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 13

Name: Hilal Rauf Subject: Basic Of .

NET Subject Code: BSIT - 61 PART: TB

Kuvempu University Assignments for B.Sc.(IT) & M.Sc.(IT) Courses Subject: Basics of .NET Subject Code: BSIT - 61 Assignment: TB (Compulsory) PART - A Answer all questions: 1. What are the advantages of using .NET ? Ans-Advantages of Using .NET: Newest technology from MS for app development Supports fully managed, but also a hybrid mix of managed and native through P/Invoke and Managed/Unmanaged C++, which means that its easier to write code that doesn't have lots of memory leaks WPF and WCF are the new way of building UI's and Communicating between processes and systems Fully integrated IDE available Linux and Mac support through 3rd parties (Mono) Many languages available, both dynamic and static (C#, VB.NET, C++), both object oriented (C#, VB.NET, C++) and functional (F#) 2. Explain .NET framework? Ans- The .NET Framework is set of technologies that form an integral part of the .NET Platform. It is Microsoft's managed code programming model 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 has two main components: the common language runtime (CLR) and .NET Framework class library. The CLR is the foundation of the .NET framework and provides a common set of services for projects that act as building blocks to build up applications across all tiers. It simplifies development and provides a robust and simplified environment which provides common services to build application. The .NET framework class library is a collection of reusable types and exposes features of the runtime. It contains of a set of classes that is used to access common functionality. 3. What is unsafe code? Explain. Ans-C# provides the ability to write unsafe code. Such code can deal directly with pointer types and object addresses; however, C# requires the programmer

to fix objects to temporarily prevent the garbage collector from moving them. This unsafe code feature is in fact a safe feature from the perspective of both developers and users. Unsafe code must be clearly marked in the code with the modifier unsafe, so developers cannot possibly use unsafe language features accidentally, and the compiler and the execution engine work together to ensure that unsafe code cannot masquerade as safe code. 4. What are the different types of arrays supported by C# programming? Ans-The different types of arrays supported by C# programming are: Single-Dimensional Arrays Multidimensional Arrays Jagged Arrays Passing Arrays Using ref and out 5. How .NET remoting different from web services and DCOM ? Ans-.NET Remoting versus Distributed COM (DCOM) In the past interprocess communication between applications was handled through Distributed Component Object Model, or simply DCOM. DCOM works well and the performance is adequate when applications exist on computers of similar type on the same network. However, DCOM has its drawbacks it relies on a proprietary binary protocol that not all object models support. It also wants to communicate over a range of ports that are typically blocked by firewalls. These are two major drawbacks of DCOM. .NET Remoting eliminates the difficulties of DCOM by supporting different transport protocol formats and communication protocols. This allows .NET Remoting to be adaptable to the network environment in which it is being used. .NET Remoting versus Web Services ASP.NET based Web services can only be accessed over HTTP. Whereas the .NET Remoting can be used across any protocol. Web services work in a stateless environment where each request results in a new object created to service the request. .NET Remoting supports state management options and can identify multiple calls from the same client. Web services serialize objects through XML contained in the SOAP messages and can thus only handle items that can be fully expressed in XML. .NET Remoting relies on the existence of the metadata within assemblies that contain

information about data types. This limited metadata information is passed about an object, when it is passed by reference. Web services support interoperability across platforms and are good for Heterogeneous environments. .NET Remoting requires the clients be built using .NET, which means a homogeneous environment.

PART - B Answer any FIVE full questions: 1. a) Write a program in C# to display Welcome to C Sharp. Explain the program. Ans-Program to display Welcome to C Sharp class Hello { static void Main() { System.Console.WriteLine("Welcome to C Sharp!); } } Explanation The important points to be noted in this program are: Comments The Main Method Input and Output Compilation and Execution b) What is the function of CTS ? Explain the classification of types in CTS with a diagram. Ans-The Common Type System (CTS) defines how types are declared, used, and managed in the runtime. It is an important for Language Interoperability. The CTS performs the following functions: Establishes a common framework that enables cross-language integration, type safety, and high performance code execution. Provides an object-oriented model. Defines rules that languages must follow, so that different languages can interact with each other. Classification of types The CTS supports two categories: 1. Value types 2. Reference types

2. a) What is operator overloading? Explain with an example. Ans-Operator Overloading- Operator overloading is a specific case of polymorphism, where different operators have different implementations depending on their arguments. Example:class MyNum { public int val; public MyNum(int i) { val = i; } { public static MyNum Add(MyNum a, MyNum b) { return new MyNum(a.val + b.val); } public static void Main(string args[]) { MyNum a = new MyNum(10), b = new MyNum(5); MyNum c = MyNum.Add(a, b); } } b) How does C# supports multiple inheritance? Ans-Multiple inheritance is not supported in C# instead we use Interfaces. The

interface keyword declares a reference type that has abstract members. Interfaces are used to define a contract; a class or struct that implements the interface must obey to this contract. Interfaces can contain methods, properties, indexers, and events as members. They cannot contain constants, fields (private data members), constructors and destructors or any type of static member. All the members of an interface are public by definition. 3. a) Write a program to C# to add two matrics. Ans-using System; class Matrix3D { // its a 3D matrix public const int DIMSIZE = 3; private double[,] matrix = new double[DIMSIZE, DIMSIZE]; // allow callers to initialize public double this[int x, int y] { get { return matrix[x, y]; } set { matrix[x, y] = value; } } // let user add matrices public static Matrix3D operator +(Matrix3D mat1, Matrix3D mat2) { Matrix3D newMatrix = new Matrix3D(); for (int x=0; x < DIMSIZE; x++) for (int y=0; y < DIMSIZE; y++) newMatrix[x, y] = mat1[x, y] + mat2[x, y]; return newMatrix; } } class MatrixTest { // used in the InitMatrix method. public static Random rand = new Random(); // test Matrix3D static void Main() {

Matrix3D mat1 = new Matrix3D(); Matrix3D mat2 = new Matrix3D(); // init matrices with random values InitMatrix(mat1); InitMatrix(mat2); // print out matrices Console.WriteLine(Matrix 1: ); PrintMatrix(mat1); Console.WriteLine(Matrix 2: ); PrintMatrix(mat2); // perform operation and print out results Matrix3D mat3 = mat1 + mat2; Console.WriteLine(); Console.WriteLine(Matrix 1 + Matrix 2 = ); PrintMatrix(mat3); } // initialize matrix with random values public static void InitMatrix(Matrix3D mat) { for (int x=0; x < Matrix3D.DIMSIZE; x++) for (int y=0; y < Matrix3D.DIMSIZE; y++) mat[x, y] = rand.NextDouble()*10; } // print matrix to console public static void PrintMatrix(Matrix3D mat) { Console.WriteLine(); for (int x=0; x < Matrix3D.DIMSIZE; x++) { Console.Write([ ); for (int y=0; y < Matrix3D.DIMSIZE; y++) { // format the output Console.Write({0,8:#.00}, mat[x, y]); if ((y+1 % 2) < 3) Console.Write(, ); }

Console.WriteLine( ]); } Console.WriteLine(); } } The output will be Matrix 1: [ 5.40, 9.89, 5.47 ] [ 7.08, 4.63, .70 ] [ .42, 5.14. 5.96 ] Matrix 2: [ 9.95, 8.76, 5.35 ] [ 8.42, 4.43, 7.53 ] [ 3.57, 7.69, 3.60 ] Matrix 1 + Matrix 2 = [ 15.35, 18.66, 10.82 ] [ 15.50, 9.07, 8.23 ] [ 3.99, 12.83, 9.56 ] b) What is data provider? Explain. Ans-Data Provider:- A .NET data provider is used for connecting to a database, executing commands, and retrieving results. Those results are either processed directly, or placed in ADO.NET Data Set. The .NET data provider is designed to be lightweight, creating a minimal layer between the data source and application code, increasing performance without sacrificing functionality.

7. a) Explain the steps involved in implementing .NET remoting applications. 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 channels. 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 listener to accept remote object requests. For this we first create an instance of the 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 the server, create an instance of the object using the server, and then execute the remote methods. iv) Test the Remoting sample : In this phase, code is tested. After the executing of code the client window will then closed while the server remain open and available. b) Explain remoting architecture. Ans- .NET remoting uses channels to communicate method calls between two objects in different application domains (AppDomains). Channels rely on formatters to create a wire representation of the data being exchanged. Below Figure shows the main elements of the .NET remoting infrastructure.

The following list briefly outlines the main components of the .NET remoting infrastructure: Channels. .NET remoting provides two channel implementations: HttpChannel TcpChannel Formatters. Each channel uses a different formatter to encode data on the wire. Two formatters are supplied: BinaryFormatter. This uses a native binary representation. SoapFormatter. This uses XML-encoded SOAP as the message format. Sinks. The .NET remoting infrastructure supports an extensibility point called a sink. The BinaryFormatter and SoapFormatter classes are examples of system-provided sinks. You can create custom sinks to perform tasks such as data compression or encryption. Proxy. Clients communicate with remote objects through a reference to a proxy object. The proxy is the representation of the remote object in the local application domain. The proxy shields the client from the underlying complexity of marshaling and remote communication protocols. Host.This is the process that hosts the remoting endpoint. Possible hosts include Internet Information Services (IIS) or custom executables such as a Windows service. The choice of host affects the type of channel that can be used to communicate with the remote object. Possible hosts include:

A Windows service application. IIS and ASP.NET. A Windows application. A console application.

8. Explain the following: a) Abstract class Ans-Abstract class: A class can indicate that it is incomplete, and is intended only as a base class for the other classes, by including the modifier abstract. Such a class is called an abstract class. An abstract class can specify abstract member. These abstract members are member that a non-abstract class must implement. Example: using System; abstract class A { public abstract void F(); } class B:A { public override void f() { Console.Writeline(B.F); } } class Test { static void Main() { B b = new B(); b.F(); A a = b; a.F; } } b) Static constructors

Ans-Static constructor: A static constructor is a member that implements that action required to initialize a class. Static constructor can't have parameters, they can't have accessibility modifiers, and they can't be called explicitly. The static constructor for a class is called automatically. c) JIT compiler. Ans-JIT Compiler: JIT stands for Just In Time compiler. The compilation converts IL into native machine code. The name Just-in-Time is because it compiles portion of the code as and when required at run time.

You might also like