Anda di halaman 1dari 11

Kuvempu University Assignments for B.Sc.(IT) & M.Sc.(IT) Courses (Academic Year 2010 - I Cycle) Subject: Basics of .

NET Subject Code: BSIT - 61 Assignment TA (Compulsory ) 1) What does .NET framework comprised off?
Ans :- Microsoft has developed .NET Framework. .NET Framework is comprised of programming methodologies like Visual Studio.NET and Mixed language programming, Platform technologies like ADO.NET, Windows Form, etc and Code Execution environment. The .Net framework has integrated few main languages and other existing technologies within it. They are C, C++, J++, VB.NET, ASP.NET, Scripting Languages- JScript.NET, ADO.NET, COM and COM+. 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) Which are the platform technologies supported by .NET framework? Ans :- The .Net framework has integrated few main languages and other existing
technologies within it. They are C, C++, J++, VB.NET, ASP.NET, Scripting LanguagesJScript.NET, ADO.NET, COM and COM+. ASP.NET :-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. COM and COM+ :-The COM+ remains as an important tool in .NET. COM works on .NET because of backward compatibility. Now on .NET Framework, calling and managing the components has become easy because .NET incorporates the COM interoperability feature. J++ :-No updating 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.

3.) How the windows programming is different from .NET programming?


Ans :- The programming on Microsoft Windows platform into two types 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 is the function of CTS? Explain the classification of types in CTS with a diagram.
Ans :- Common Type System (CTS):- This is a standardized agreed set of basic data types. This system provides a way for language interoperability. Language Interoperability means that a object implemented in one language can call a object implemented in another language. In more general way you can say that a application can be developed in two or more languages supported by .Net framework. To make use of language interoperability feature, the developers have to follow CTS. Classification of types The CTS supports two categories:1. Value types:- Value types directly stores data in the variable. Value types can be built-in type, user-defined types, or enumerations. 2. Reference types:- Reference types store a reference to the datas memory address. Reference types can be self describing types, pointer types, or interface types. Self-describing types are further split into arrays and class types. The class types are user-defined classes, boxed value types, and delegates.

3) What are assemblies? What are static and dynamic assemblies?


Ans :- Assembly is a basic element of packaging in .NET. An assembly consists of IL code, metadata that describes what is in the assembly, and any other files or information that the application needs to run, such as graphics and sound files. Assemblies can be static or dynamic. Static assemblies can include .NET types (interfaces and classes), as well as required resources for the assembly (bitmaps, JPEG files, resource files, and so on). Static assemblies are stored on disk in PE files. Dynamic assemblies are one which run directly from memory and are not saved to disk before execution. They can be saved disk after they have executed.

4) 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) { } } }

5) 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. namespace ABC // ABC { class Class1 // ABC.Class1 { }} namespace XYZ // XYZ { class Class1 // XYZ.Class1 { }} From the above code example: The namespace ABC is a member of the global namespace. Its fully qualified name is ABC. The namespace XYZ is a member of ABC. Its fully qualified name is ABC.XYZ. The class Class1 is a member of the ABC. Its fully qualified name is ABC.Class1. The class name Class2 is used twice in this code. However, the fully qualified names are unique. The first one is declared inside Class1; thus its fully qualified name is: ABC.Class1.Class2. The second is declared inside a namespace XYZ; thus, its fully qualified name is ABC.XYZ.Class2.

6) 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 System. Delegate. 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. The example class Test

{ static void F() { System.Console.WriteLine(Test.F); } static void Main() { SimpleDelegate dele = new SimpleDelegate(F); dele(); } }

7) 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. 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; } } }
8) 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. For instance, a framework might define a Help Attribute that can be placed on program elements (such as classes and methods) enabling developers to provide a mapping from program elements to help documentation for them. The example using System; public class HelpAttribute: Attribute { public HelpAttribute(string url) { this.url = url; } public string Topic = null; private string url; public string Url { get { return url; } } }

Assignment: TB (Compulsory) 1.What are events? Give an example to demonstrate its usage.
Ans :- An event is a member that enables an object or class to provide notifications. A class defines an event by providing an event declaration and an optional set of event assessors. The declaration resembles a field declaration, though with an added event keyword. The type of this declaration must be a delegate type. An instance of a delegate type encapsulates one or more callable entities. 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. For example:public delegate void EventHandler(object sender, System.EventArgs e); public class Button { public event EventHandler Click; public void Reset() { Click = null; } }

2.With an example explain indexers?


Ans :- An indexer enables an object to be indexed in the same way as an array. Whereas properties enable field-like access, indexers enable array-like access. As an example, consider the Stack class presented earlier. The designer of this class might want to use array like access so that it is possible to manipulate the items on the stack without performing unnecessary Push and Pop operations.

That is, class Stack is implemented as a linked list, but it also provides the convenience of array access. Indexer declarations are similar to property declarations, with the main differences being that indexers are nameless and that indexers include indexing parameters. The indexing parameters are provided between square brackets.

3.How C # does support inheritance?


Ans :- C# classes support single inheritance, and the type object is the ultimate base class for all classes. The classes shown in earlier examples all implicitly derive from object. The example shows a class A that implicitly derives from object. The example class Employee { private static DataSet ds; static Employee() { ds = new DataSet(...); } public string Name; public decimal Salary; ... } using System; class A { public void F() { Console.WriteLine(Inside A.F); } } class B: A { public void G() { Console.WriteLine(Inside B.G); } } class Test { static void Main() { B b = new B(); b.F(); // Inherited from A b.G(); // Introduced in B A a = b; // Treat a B as an A a.F(); } } shows a class B that derives from A. The class B inherits As F method, and introduces a G method of its own. Methods, properties, and indexers can be virtual, which means that their implementation can be overridden in derived classes.

4.What are the different methods supported by system. Object class? Give an example for each.
Ans :- System. Object class is the ultimate base class that all types directly or indirectly derive from. The object class allows us to build generic routines, provides Type System Unification, and enables working with groups collections. The object class also facilitates using any type in a collection. It contains methods that can be reused or overridden in base types. Since collections,

such as Hashtable and ArrayList accept object types, we can add any type to them. The Equals, GetType, and GetHashCode object class methods are called directly by the collection classes. The Equals Method:- The Equals method of the object class provides a default implementation that compares two reference type objects for reference equality. For example using System; class Employee { string e_name; public Employee(string name) { e_name = name; } } class EqualsDemonstration { static void Main() { EqualsDemonstration eqDemo = new EqualsDemonstration(); eqDemo.InstanceEqual(); Console.ReadLine(); } public void InstanceEqual() { string name = Joe; Employee employee1 = new Employee(name); Employee employee2 = new Employee(name); // comparing references of separate instances bool isEqual = employee1.Equals(employee2); Console.WriteLine(employee1 == employee2 - {0}, isEqual); employee2 = employee1; // comparing references of the same instance isEqual = employee1.Equals(employee2); Console.WriteLine(employee1 == employee2 - {0}, isEqual);} } The ToString Method:- The purpose of the ToString method is to return a string representation of a type. The default implementation in the object class returns a string with the name of the object. For example using System; class Employee { string e_name; public Employee(string name) { e_name = name; } // If ToString() is not overridden, the output of this program will be Employee. public override string ToString() { return String.Format([Employee: {0}], e_name); } } class ToStringDemonstration { static void Main() { Employee emp = new Employee(Joe); Console.WriteLine(emp.ToString()); Console.ReadLine(); } } The Finalize Method:- the Finalize method as a destructor. The original purpose of the destructor was to serve as a place where we can release unmanaged resources such as network connections, operating system resources, or file streams. However, in practice we never want to use the destructor. The reason is that a destructor is executed automatically by the garbage collector. For example using System; class Employee { string e_name; public Employee(string name)

{ e_name = name; Console.WriteLine(Employee Name: {0}, e_name); } ~Employee() { Console.WriteLine(Employee destructor executed.); } } class DestructorDemonstration { static void Main(){ Employee emp = new Employee(Joe); } } The GetType Method:- GetType is the basis for using reflection in .NET. It returns a Type object, describing the object it was called on. It can then be used to extract type member data like methods and fields that may subsequently be used for late-bound method invocations. For example using System; class Employee { } class GetTypeDemonstration { static void Main() { object emp1 = new Employee(); Employee emp2 = new Employee(); Console.WriteLine(emp1.GetType()); Console.WriteLine(emp2.GetType()); Console.ReadLine(); } }

Write a program to replace r by R in the string rose is a rose. Ans :-

What is the use of System Collection class? Ans :- The System. Collections namespace contains interfaces and classes that define various
collections of objects, such as lists, queues, bit arrays, hash tables and dictionaries. Each class has a set of methods and properties, which are used on those corresponding class objects.

What is 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 an 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.

What is a data set? Explain. Ans :What is the role of System.web? Ans :Write a program to demonstrate handling of server control events. Ans :-

Anda mungkin juga menyukai