Вы находитесь на странице: 1из 14

Basics of .Net BScIT-61 Assignment TA 1. What does .NET framework comprised of? Ans: The .

NET Framework is an environment for the developers. It mainly comprised of programming methodology and technologies. The .NET Framework comprises of Programming Methodologies: On the Programming Methodology side, an interesting thing about .NET is that it allows for mixed-language programming. By designing from the ground up a specification that is common to all the languages that work in .NET Framework, by designing a type system that all those languages support, and by specifically designing an intermediate language that all those languages compile into; before they compile in native code. Platform Technologies: In Platform technologies, we will mainly go through ADO.NET, Internet technologies and User interface designing. The following paragraphs talks about these topics. Code Execution: The interesting thing about code execution on .NET framework is, when we hear about .NET, we think, that it is particular to Intel-based computers. But it is certainly not. The standardized common language infrastructure is completely architectureneutral. 2. Which are the platform technologies supported by .NET framework? Ans: The technologies supported by the .NET framework are: C# C# is a new language developed with .NET and for .NET platform. It is a new language, which is capable of using all services provided by Dot Net platform. C# compiler always produces managed code after compilation. C++ Even with new and more powerful language C#, .Net also supports C++ because of backward compatibility. Many features are added to the C++ to make it stronger on .Net framework. To run a C++ code on .Net framework, we need to include below line at the beginning of the code. J++ No updations are made to this language. It is supported on .Net only for backward compatibility. There is much similarity between the J++ and C# syntax, So a tool which converts the J++ code to C# code is provided by .NET. Using this tool we can use convert J++ application to C# and use the facilities provided to C# language.

VB.NET Visual Basic is been upgraded to Visual Basic.Net (VB.NET) on .Net Framework. Many new features and many new controls are added. Good debugging facility is provided. The compiled code of VB.NET is intermediate code as in the case of C#. The VB applications also work on VB.NET as the backward compatibility does exist. ASP.NET (Active Server Pages) ASP is upgraded to ASP.NET on .Net Framework. The coding can be done directly in any of C#, VB.NET or JScript.NET. The code is compiled into classes which respond to the web requests. Because of backward compatibility the ASP code still continues to run on this new platform. ADO.NET (Active Data Objects) ADO.NET has been added new features like communicating with data sources which is made easy. ADO.NET is now the subset of .NET Base Classes. 3. How is the windows programming is different from .NET programming? Ans: In Windows Programming the application programs call windows API function directly. The applications run in the windows environment i.e. operating system itself. These types of applications are called unmanaged or unsafe applications. In .NET Programming the application programs call .Net Base Class library functions which will communicate with operating system. The applications run in .Net Runtime environment. These types of applications are called as managed or safe applications. The .Net Runtime starts code execution, manages threads, provides services, manages memory etc. The detailed description is provided in next section. The .Net Base classes are fully object-oriented. It provides all functionalities of traditional windows API along with functionalities in new areas like accessing database, Internet connections and web services. 4. What are 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 eachother. Classification of types The CTS supports two categories: 1. Value types

2. Reference types

5. What are assemblies? What are static and dynamic assemblies? Ans: An Assembly is the unit in which compiled managed code is stored. An Assembly contains IL and metadata. Metadata gives details of the assembly, properties and methods stored in it, security information etc. 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 portable executable (PE) files. 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. 6. Explain general structure of c#? Ans: C# program can consist of one or more files. Each file can contain one or more namespaces. A namespace contains group of related types such as classes, structs, interfaces, enumerations, and delegates. Namespaces may be nested. The following is the skeleton of a C# program that contains all of these elements. // A skeleton of a C# program using System; namespace Namespace1 { class Class1 {

} struct Struct1 { } interface Interface1 { } delegate int Delegate1(); enum Enum1 { } namespace Namespace2 { } class Class2 { public static void Main(string[] args) { } } } 7. How do namespaces and types in c# have unique names? Give examples. Ans: Fully Qualified Names describe the logical hierarchy of the type or object. Namespaces and types always have unique names. For example, If there are 2 class with same name but are present in different namespaces then both the objects will have their unique fully qualified names. 8. What is delegate? What is the use of it? Give example. Ans: A delegate is a C# language element that allow us to reference a method. For a C or C++ programmer, this is a familiar because a delegate is basically like a function pointer. However, unlike function pointers, delegates are object-oriented and type-safe. A delegate declaration defines a class that is derived from the class SystemDelegate. A delegate 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 instance and a method on that instance. For static methods, a callable entity consists of just a method. Given a delegate instance and an appropriate set of arguments, one can invoke all of that delegate instances methods with that set of arguments.

There are three steps in defining and using delegates: declaration, instantiation, and invocation. Delegates are declared using delegate declaration syntax. The example delegate void SimpleDelegate(); declares a delegate named SimpleDelegate that takes no arguments and returns no result. The example class Test { static void F() { System.Console.WriteLine(Test.F); } static void Main() { SimpleDelegate dele = new SimpleDelegate(F); dele(); } } creates a SimpleDelegate instance and then immediately calls it. There is not much point in instantiating a delegate for a method and then immediately calling that method via the delegate, as it would be simpler to call the method directly. Delegates really show their usefulness when their anonymity is used. The example void MultiCall(SimpleDelegate dele, int count) { for (int i = 0; i < count; i++) { dele(); } } 9. Write a program to demonstrate use of enums in C#? Ans: An enum type declaration defines a type name for a related group of symbolic constants. Enums are used for multiple choice, in which a runtime decision is made from a fixed number of choices that are known at compile-time. The example

enum Color { Red, Blue, Green } class Shape { public void Fill(Color color) { switch(color) { case:Color.Red: Console.WriteLine(RED); break; case:Color.Blue: Console.WriteLine(BLUE); break; case:Color.Green: Console.WriteLine(GREEN); break; default: break; } } } 10. What is the use of attributes in C# programs? Ans: C# is an imperative language, but like all imperative languages it does have some declarative elements. For example, the accessibility of a method in a class is specified by declaring it public, protected, internal, protected internal, or private. C# generalizes this capability, so that programmers can invent new kinds of declarative information, attach this declarative information to various program entities, and retrieve this declarative information at run-time. Programs specify this additional declarative information by defining and using attributes.

Assignment: TB PART A 1. What are the advantages of using .NET ? Ans: The advantages of .NET Framework are: Provides Consistent Programming Model Has Language Independence No versioning Problem - Easy Application Deployment and Maintenance Improved Security Support for Web Services Dynamic Web facilities Full fledged Visual Studio.NET 2. Explain .NET framework? Ans: The .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability. Programs written for the .NET Framework execute in a software environment, known as the Common Language Runtime (CLR), an application virtual machine that provides important services such as security, memory management, and exception handling. The class library and the CLR together constitute the .NET Framework. The .NET Framework's Base Class Library provides user interface, data access, database connectivity, cryptography, web application development, numeric algorithms, and network communications. Programmers produce software by combining their own source code with the .NET Framework and other libraries. The .NET Framework is intended to be used by most new applications created for the Windows platform. Microsoft also produces a popular integrated development environment largely for .NET software called Visual Studio.

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 can not 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 1.a) Write a program in C# to display Welcome to C Sharp. Explain the program. Ans: // A Simple "Hello World!" string display program in C# class Hello { static void Main() { System.Console.WriteLine("Welcome to C Sharp!); } } The important points to be noted in this program are: Comments The Main Method Input and Output Compilation and Execution 1.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 is a specific case of polymorphism, where different operators have different implementations depending on their arguments. 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); } }

2.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 can not 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) 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()

Write a program to C# to add two matrics.

{ 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, 7.08, .42, 9.95, 8.42, 3.57, 9.89, 4.63, 5.14. 8.76, 4.43, 7.69, 5.47 .70 5.96 5.35 7.53 3.60 ] ] ] ] ] ]

Matrix 2:

Matrix 1 + Matrix 2 = [ [ [ 15.35, 18.66, 10.82 ] 15.50, 9.07, 3.99, 8.23 ] ] 12.83, 9.56

3b)

What is a data provider? Explain. Ans: 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 DataSet. 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.

44 What is the role of System.Web? Ans: The System.Web namespace supplies classes and interfaces that enable browser and server communication. This namespace includes the HttpRequest class which provies extensive information about the current HTTP request, the HttpResponse class which manages HTTP output to the client, and the HttpServerUtility class which provides access to server-side utilities and process. System.Web also includes classes for cookie manipulation, file transfer, exception information, and output cache control. 44 Explain the following: 1. 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; } }

2. 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. 3. 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.

Вам также может понравиться