KUVEMPU UNIVERSITY 6th SEM Sample Paper

KUVEMPU UNIVERSITY 6th SEM Sample Paper

                                                      BASICS OF .NET

Long question answer

1. What is .NET frame work? Explain.

Ans:- The .NET framework is one of the tool provided by Microsoft corporation. This is a software framework that includes everything required for developing software for web services. The .NET platform provides a new environment for creating and running robust, scalable and distributed application over the web. It is designed to make significant improvements in code reuse, code specialization, resource management, and Multilanguage development.

It consists of three services:–

a).NET Product: It consists of Visual Studio .NET, Visual Basic, Visual C#, and Visual C++.

b) .NET Services: .NET helps you to create software as a web services. Microsoft has its own set of web services called My Services.

c) .NET framework: It is a foundation on which you design, develop, and deploy applications. It is consistent and simplified programming model that helps you to easily build robust application.

.Net framework has several components such as Window form, Console application, Web forms and web services, Base class library and Common language runtime.

2. What are the advantages of using .NET frame work?

Ans: Following are the main advantages of .NET framework:–

  • Consistent programming model:- It provide a common object-oriented programming model across languages. This object model can be used to perform several tasks such as reading from and writing to file, connecting to databases, and retrieving data.
  • Multi-platform application:- A .NET application can execute on any architecture or environment that is supported by the CLR.
  • Multi-language integration:-  .NET allow multiple language to be integrated. We can create a object in any language that is derived from a class implemented in any other languages. To enable objects to interact with each other a set of language features has been defined in CLS. CLS enhances language interoperability.
  • Automatic resource management:– CLR is a important component of .NET framework. It manages all resources such as file, memory, network connection, and database resources automatically without writing the code.
  • Ease of development:–  .NET applications can be deployed simply by copying files to the target computer. The .NET framework provides zero-impact deployment means that installation of new applications or components does not have an adverse effect on the existing applications.
  • Web services:- With the advent of .NET technology, web services provide many built in Base Class Library facility which open up a whole world of information for the users. Web services provide everything from basic text news information to vital database or application information.

3. How does string handle in C# ? Explain.

Ans: String is a sequence of characters. It is the easiest way to represent a sequence of characters in C#.  In C# string is uses to create a string type objects. It is an alias to the System.String type. String type is immutable means that once it has been created, a string cannot be changed. No modification in the string will take place. Ex: Insert () method of string class

 

using System;

class str   {

public static void Main()   {

string s1 = “Lean”;

string s2 = s1.Insert ( 3, “r”);

string s3 = s1.Insert (5, “er”);

for  (int I =0; i>s3.Length; i++ )   {

Console.Write(s3[i]);

Console.WriteLine();

}}

 

 

4. Explain working of switch statement.

Ans: A switch statement executes the statements that are associated with the value of a given expression. It checks the values of a given variable against a list of case values and when a match is found, a block of statements associated with that case is executed.

Following example demonstrate the working of switch statement:

 

using System;

class CityGuide  {

public static void Main()  {

Console.WriteLine(“ Select your choice”);

Console.WriteLine(“ London”);

Console.WriteLine(“ Bombay”);

Console.WriteLine(“ Paris”);

Console.WriteLine(“ Type your choice”);

String name = Console.ReadLine();

switch (name)   {

case “Bombay”:

Console.WriteLine(“ Bombay: guide 5”);

break;

case “London”:

Console.WriteLine(“ London: guide 10”);

break;

case “Paris”:

Console.WriteLine(“ Paris: guide 12”);

break;

default:

Console.WriteLine(“ Invalid choice”);

break;

}}}


5. Write an ASP. NET program to demonstrate handling of server control events.

Ans: Server control is capable of exposing an object model containing properties, methods and events in ASP.NET. Developers use this object model to cleanly modify and interact with the page.

Following program shows the handling of server control event:-

 

 

 

 

 

Name:

Category:

Math

English

Science

 

 

6. Compare the features of C++ with C# programming.

Ans: i) C++ support object-oriented programming while C# is purely object-oriented language.

ii) The syntax for declaring array follows the token ’[]’ in C#  which is different from C++.

iii) There is no conversion between the bool type and int in C#.

iv) In C#, the long data type is 64 bits, while in C++, it is 32 bits.

v) C# supports additional operator such as is and typeof while C++ doesn’t supports them.

vi)C# strings are different from C++ string.

vii) In C# Main method is declared differently from the main function in C++.

viii) Like C++, no header files or #include directives in C#.

ix) Operator overloading is performed differently in C# from C++.

x) Unlike C++, if you don’t provide a class constructor in C#, a default constructor is automatically generated for.

 

7. Explain how to use multiple threads in program with example.

Ans: Following code shows the use of multithread in program:-

 

using System;

using System.Threading;

class threads {

public static void ChildThread1() {

Console.WriteLine(“This is child thread”);

Console.WriteLine(“child thread- counting from 1to 5”);

for (int T=1; T

for (int Cnt=0; Cnt

Console.Write(“.”);  }

Console.Write(“{0}”,    T);   }

Console.WriteLine(“child thread ending”); }

Public static void ChildThread2() {

Console.WriteLine(“This is child thread2”);

Console.WriteLine(“child thread2- counting from 6 to 10”);

for (int T=6; T

for (int Cnt=0; Cnt

Console.Write(“.”);  }

Console.Write( “{0}”,    T);   }

Console.WriteLine(“child thread2 ending”);   }

Public static void Main()  {

ThreadStart Child1 = new ThreadStart (ChildThread1);

ThreadStart Child2 = new ThreadStart (ChildThread2);

Console.WriteLine(“This is creating child thread”);

Thread Thread1 = new Thread(Child1);

Thread Thread2 = new Thread(Child2);

Thread1.Start();

Thread2.Start();  }}

 

8. What are the advantages of using multiple threads in program?

Ans: Threads are the basic unit to which an operating system allocates processor time, and more than one thread can run inside that process. Each thread maintains exception handlers, a scheduling priority, and a set of structures the system uses to save the thread context until it is scheduled.

Multithreading offers the following advantages:

i)Improved responsiveness: If the application is performing operations that take a perceivably long time to complete, these operations can be put into a separate thread which will allow the application to continue to be responsive to the user.

ii) Faster application: Multiple threads can lead to improved application performance. For example, if there are a number of calculations to be performed, then there the application can be made faster by performing multiple operations at the same time.

iii) Prioritization: Threads can be assigned a priority which would allow higher priority tasks to take precedence over lower priority tasks.

iv) It communicates over a network, to a web server and to a database.

9. a) Explain exception handling techniques.

Ans: An exception is any error condition or unexpected behavior encountered by a program in execution. Exception can be raised because of fault in our code or shared library.

Exceptions are handled by a try statement. When an exception occurs, the system searched for the nearest catch block that can handle the exception. Once a matching catch block is found the control is transferred to the first statement of the catch block and the catch block executes. If no matching catch block is found, then the execution of the thread is terminated. Some exception objects are- System.AirthmeticException, System.DivideByZeroException.

10. Write a program in C # to display ‘Welcome to World of C sharp’ Explain the program?

Ans:- using System;

namespace Welcome

{

class Hello

{

public static void Main()

{

Console.WriteLine(“Welcome to the world of C Sharp”);  }}}

11. Explain how to create user defined exceptions with an example.

Ans: User defined exception classes are derived from the ApplicationException class. Following code creates a user defined exception named CountIsZeroException.

 

using System;

namespace UDExc   {

class CountZero  {

public static void Main(string[] args)  {

Calcute calc = new Calcute();

Try  {

Calc.DoAverage();  }

Catch (CountIsZeroException e)  {

Console.WriteLine(“CountIsZeroException: {0}”,e.Message);  }

Console.ReadLine();  }}}

Public class CountIsZeroException: ApplicationException  {

Public class CountIsZeroException(string message) : base (message)  { }}

Public class Calculate  {

Int sum = 0;

Int count = 0;

Float average;

Public void Doaverage()  {

If  (count === 0)

Throw (new CountIsZeroException(“zero count in average”) );

Else average = sum/count;  }}

 

12. What is .NET framework? Explain architecture of .NET frame work.

Ans: The .NET framework is one of the tools provided by Microsoft Corporation. This is a software framework that includes everything required for developing software for web services. The .NET platform provides a new environment for creating and running robust, scalable and distributed application over the web. It is designed to make significant improvements in code reuse, code specialization, resource management, and Multilanguage development.

Architecture of .NET framework:-

                     .NET  Framework
VB.NET C# Jscript.NET Other .NET language
ASP .NET

(Web Services)

Widows Forms (User Interface) Console

 

ADO .NET .NET Remoting
                        Framework Class library
                    Common Language Runtime

i)It consists of several languages and web services such as C#, VB.Net, Jscript.Net, ASP.Net, ADO.Net etc.

                  Operating System

ii) Common Language Runtime: This is the most essential component of the .Net framework. It is the environment where all programs using .Net are executed. It provides services such code compilation memory allocation, and garbage collection. It also provides a set of rule known as CTS.

iii) Framework class Library: This library works with any .Net languages. It provides classes that can be used in the code to accomplish a range of common programming tasks such as string management, data collection, database connectivity etc.

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

Ans: Attribute is declarative tag that is used to convey information to runtime about the behavior of programmatic element such as classes, enumeration and assemblies. Attributes are used for adding metadata. Attributes are applied to different element of the code. Attributes might require one or more parameter. Some predefined attribute used by C# are:- i)  Conditional:- It causes conditional compilation of method calls, depending on specified value.

ii) WebMethod:- It identifies the exposed method in a web service.

iii) DllImport:- It calls an unmanaged code in programs developed outside the .Net environment.

iv) Obsolete:- It enables programmer to inform the compiler to discard a piece of element like method of a class.

 

 

 

 

13. What is the function of CTS? Explain the classification of types in CTS with a diagram?

Ans: Functions of CTS are: – i) Establishing a common framework that enables cross language integration, type safety, and high performance code execution. ii) Providing an object-oriented model. iii) Defining rules that languages must follows, so that different languages can interact with each other.

  Type

Types in CTS:-

Value Types

Reference Types

Built-in Value Types

User-Defined Value Types

Enumeration

Self Describing                                                             Types

Pointer

Interface

Class Types

Arrays

User-Defined Classes

Boxed Value Types

Delegates

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Reference type:-

Value type:-

14.a) What is operator overloading? Explain with an example.

Ans: Operator overloading is a way that allows operator to work with user defined data type in the same way as the built-in data types. It provides a flexible option for the creation of new operator definitions’ in C#.

 

Example: Code for overloading minus (-) operator:–

using System;

class Calculator  {

public int number1, number2;

public Calculator(int num1, int num2)  {

number1=num1;

number2=num2;  }

public static Cclculator operator –(Calculator c1)  {

 

c1.number1 = -c1.number1;

c1.number2 = -c1.number2;

return c1;   }

public void print ()   {

Console.WriteLine(“number1=” + number1);

Console.WriteLine(“number2=” + number2);

Console.ReadLine();    }  }

Public static void Main()   {

Calculator  calc = new Calculator (15, -20);

calc = -calc;

calc.Print();  }}


b) How does C# supports inheritance?

Ans: Inheritance is the property by which the objects of a derived class possess copies of the data members, and the member functions of the base class. C# supports single inheritance.

C# classes support inheritance by using the ‘:operator.

Consider the following example it shows a class B that derives from A. The class B inherits A’s F method, and introduces a G method of its own.

 

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   {

public  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();

 

}

 

15. Explain different types of arrays present in C#  with an example.

Ans: An array is a data structure that contains a number of variables called the element of the array.

Following types of arrays present in C#:- i) Single dimensional array:- A list of items can be given one variable name using one subscript and such a variable called single dimensional array.

ii) Multi dimensional array:- When array variables store a list of value then it is said to be a multi dimensional array.

iii) Jagged array:- This is an array whose elements are arrays. The element of a jagged array can be of different dimension and size. It is also called an “array of array”. Ex: It shows the declaration of single dimensional array and its initializing in jagged array:-

int [] [] myJaggedArray = new int[3][];

Initializing:

myJaggedArray[0] = new int[5];

myJaggedArray[1] = new int[4];

myJaggedArray[2] = new int[3];

iv) Passing arrays using ref and out:An out parameters of array type must be assigned before it is used in a program. it must be assigned by the calle.

Ex: public static void MyMethod(out int[] arr){

arr= new int [10];  // definite assignment of arr

}

A ref parameter of array type must be definitely assigned by the caller. So, there is no need to be definitely assigned by the callee. A ref parameter of an array type may be altered as a result of the call. The array can be assigned the null value or can be initialized to a different array.

Ex: public static void MyMethod (ref int[] arr){

arr = new int[10]; }

16. What is data provider? Explain.

Ans: Data Provider:- A data provider is used for connecting to a database, executing commands, and retrieving information. A data provider is designed to be lightweight, creating a minimal layer between the data source and application code, increasing performance without sacrificing functionality. Main component objects of data provider are:-

i) Connection:- It establishes a connection to a specified data source.

ii) Command:- It executes a command against a data source.

iii) DataReader:- It reads a forward-only, read-only stream of data from a data source.

iv) DataAdapter:- It populates a DataSet and resolves updates with the data source.

18. Explain in detail ADO.NET architecture.

Ans: ADO (ActiveX Data Object).NET is a set of classes that provide data access to the .Net programmer. It has a rich set of components for creating distributed, data-sharing applications..

The ADO.Net components have designed fr easy data access and manipulation.

There are two central components of ADO.Net:-  a) DataSet:- It is the core components of the disconnected environment of ADO.NET. It is explicitly designed for data access independent of any data source. It can be used with multiple and different data sources, used with XML data, or used to manage data local to the application. It contains a collection of one or more data table objects as well as primary key, foreign key, constrain, and relation information about the data.

b) Data Provider:- It is the also a other core element of ADO.NET.  Its components (Connection, Command, DataReader, and DataAdapter) are explicitly designed for data manipulation and forward-only, read-only access to data.

Command object enables access to database commands to return data, modify data, run stored procedure.

Connection object provides connectivity to a data source.

DataReader provides a high performance stream of data from the data source.

DataAdapter provides the bridge between the DataSet object and the data source.

19. Write a program to display “Welcome to ASP.NET” 8 times in increasing order

of their font size using ASP.NET.

Ans: The following program displays “Welcome to ASP.NET” eight times in increasing order of their font size.

In the following code, the Web application name Webapps is application specific:

 

 

 

 

WebForm1

 

 

 

 

Welcome to ASP.NET ASHISH

 

 

</html>

b) What is the role of system web?

Ans: The System.Web is a namespace that supplies classes and interfaces that enables browser and server communication. This namespace includes the HttpRequest class which provides 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 processes. The System.Web also includes classes for cookies manipulation, file transfer, exception information, and output cache control.

20. a) Explain the steps or phases 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: The remoting architecture consists of the remote component, server, client, and a channel (transportation medium).

i) The remote component is the object that provides services to the client. The remoting system uses proxy objects to create the impression that the server object is in the client’s process. Proxies are stand-in objects that present themselves as some other object. When the client creates a remote instance, the remoting infrastructure creates a proxy object that looks to our client exactly like the remote type.

ii) The server creates and register a channel, which is a transportation medium, to listen at a specified port. The server also registers the remote object.

iii) A channel is a transportation medium through which communication between a server and a client takes place. It takes a stream of data, creates a package according to a particular network protocol, and sends the package to another computer.

iv) The client requests for the services of a remote object. A client can choose the registered channels on the server to communicate with the remote object.

21. Write a program to C# to add two matrices’.

Ans:

22. Write a program in C# to check a given string is palindrome or not.

Ans:

22.b)Explain different string functions supported by C#?

Ans: Followings string methods are supported by C#:-

i)Compare ():- It is used to compare two strings. ii) CompareTo ():- it compares the current instance with another instance. iii) ConCat ():- It concatenates two or more strings. iv) Copy ():- It creates a new string by copying another. v) EndsWith ():- It determines whether a substring exists at the of the string. vi) Equals ():- It determines if two strings are equals. vii) IndexOf ():- It returns the position of the first occurrence of a substring. viii) Insert ():- It returns a new string with a substring inserted at a specified location. ix) Split ():- It creates an array of strings by splitting the string at any occurrence of one or more characters. x) StartWith ():- It determines whether a substring exists at the beginning of the string.

23. Define the following: — i) CLR: It stands for Common Language Runtime. CLR is a runtime environment in which programs written in C# and other .NET languages are executed. It provides services such as: – Loading and executing of programs, Memory isolation for application, Managing exceptions and errors, providing metadata, and verification of type safety etc. CLR supports cross-language interoperability. Some components of CLR are: – Common Type System, Intermediate Language, Garbage collection, Class loader, and Memory layout.

ii)  CTS: It stands for Common Type System. It defines how types are declared, used, and managed in the runtime. Its main functions are: – i) Establishing a common framework that enables cross language integration, type safety, and high performance code execution. ii) Providing an object-oriented model. iii) Defining rules that languages must follows, so that different languages can interact with each other.  

iii) CLS: It stands for Common Language Specification. It defines a set of rules that enables interoperability on the .NET platform. These rules serve as a guide to third party compiler designers and library builder. The CLS is a subset of CTS means all the rules that apply to the CTS also apply to the CLS.

24. Mention the important features of C#.

Ans: Important feature of C#:– i) It is a simple and consistent programming language. C# supports a unified type system which eliminates the problem of varying range of integer types. All types are treated as object so developer extends the type system simply and easily.

 ii) It is a modern language because it supports automatic garbage collection, robust security model, modern approach to debugging etc.

iii) C# supports all three tenets (Encapsulation, Inheritance, and Polymorphism) of object- orientation.

iv) C# supports type safety because; it does not permit unsafe code, and all dynamically allocated objects and arrays are initialized to zero.

v) C# provides support for versioning with the help of new and override keywords. Through this feature new software works with existing application easily.

vi) C# supports interoperability and platform independency because it  is compatible with COM and .NET framework services through tight .NET Base Class Library.

24.b) What is IIS server? Why it is used?

Ans:

25. What is the role of the following :

i) System. Object: System.Object class is the ultimate base class that all types directly or indirectly drive from. The object class allows us to build generic routines, which provides Type System Unification, and enables working with groups collections.

Reference types inherit the object class through other reference types while Value types inherit from System.ValueType, which inherits from System.Object. The object class also allow of using any type in a collection. It contains methods such as Equals, GetType, GetHashCode, MemberwiseClone and Finalize methods that can be reused or overridden in base types. 

ii) System. Collection: The System. Collections namespace contain s 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.

Following are some classes of System.Collection namespace:–

i)ArrayList: – The IList interface used in which array whose size is dynamically increased as required.

ii)BitArray: – It manages a compact array of bit values, which are represented as Booleans.

iii)CollectionBase: – It provides the abstract base class for a strongly typed collection.

iv)DictionaryBase: – It provides the abstract base class for a strongly typed collection of key-and-value pairs.

v)Hashtable: – It represents a collection of key-and-value pair that are organized based on the hash code of the key.

iii) System. String: System.String is a buit-in type provided by .NET framework. When a string is created every times System.String object is instantiated. String data type is an alias to the System.String type. Along with the instance member, the System.String class has a few important static methods. These methods do not require a string instance to work. Some of the methods of this class are:- Compare(), CompareTo(), Copy(), Insert() etc.        

iv) System. Drawing

26. With the help of an example explain the following:

i) Jagged arrays: A jagged array is an array whose elements are arrays. The elements of jagged array can be of different dimensions and sizes. A jagged array is also called an “array-of-arrays”. Jagged array must be initialized before use in program.


Ex :  using System;

pubic class JaggedArray{

public static void Main(){ 

// declaring the jagged array of two elements:

int [][] myArray =new int[2][];

  // initializing the element:

myArray[0] = new int[5] {1,3,5,7,9};

myArray[1] = new int[4] {2,4,6,8};

// display the array element:

For (int i=0; i

Console.Write(“Element is({0})”,i++);

For (int j=0; j

Console.Write(“{0}{1}”,myArray[i][j],j==(myArray[i].Length-1) ? “”: “”);

Console.WritelLine();

}}}         


ii) Passing arrays using ref and out:

Ans: An out parameters of array type must be assigned before it is used in a program. it must be assigned by the calle.

Ex: public static void MyMethod(out int[] arr){

arr= new int [10];  // definite assignment of arr  }

A ref parameter of array type must be definitely assigned by the caller. So, there is no need to be definitely assigned by the callee. A ref parameter of an array type may be altered as a result of the call. The array can be assigned the null value or can be initialized to a different array.

Ex: public static void MyMethod (ref int[] arr){

arr = new int[10]; }

27.  What are events? Give an example to demonstrate its usage.

Ans: An event is a set of actions that is triggered to call a function or to start an operation. A class defines an event by providing an event declaration and an optional set of event assessors. The declaration resembles a field declaration, with an added event keyword. The type of this declaration must be a delegate type.

Consider the following example:

public static void Button1_Click (object sender, EventArgs e)

{

MessageBox.Show (“Button1 was clicked!”);

}

In the above example, a click event is raised when Button1 is clicked.

6) a) What is threading ? List the advantages of using threading.

Ans: Threading: Threads are the basic unit to which an operating system allocates processor time, and more than one thread can run inside that process. The process of developing a program using a thread is called threading.

Advantages of thread: i) It provides communication over a network, to a web server and to a database.

ii) It performs operations that take a large amount of time.

iii) It distinguishes the task on the basis of priority. Ex- a high-priority thread manages time-critical task and a low priority thread performs other task.

iv) It allows the user interface to remain responsive, while allocating time to background tasks.

b) What are interfaces? Explain the use of interfaces with the help of an example?

Ans: Interface:- Interface is used to define a class or struct that implements the interface. Interface contains methods, properties, indexers, and events as members. The interface keyword declares a reference type that has an abstract member. They do not contain any private data member and any type of static member. All the members of an interface are public.

Example: Implementation of interface

 

using System;

interface Addition  {

int Add();   }

interface Multiplication  {

int mul ();   }

class Computation : Addition, Multiplication   {

Int x, y;

public Computation (int x, int y)   {

this.x = x;

this .y =y;    }

public int Add ()   {

return (x+y);

public int Mul ()  {

return (x * y);    }}

class test   {

public static void Main ()    {

Computation com = new Computation (10, 20);

Addition add = (Addtion) com;

Console.WriteLine (“sum =” + add.Add ());

Multiplication mul= new (Multiplication)com;

Console.WriteLine (“product =” + mul.Mul ());

}}


 

8) Write short notes on:–

i) Data Provider: Data Provider:- A data provider is used for connecting to a database, executing commands, and retrieving information. A data provider is designed to be lightweight, creating a minimal layer between the data source and application code, increasing performance without sacrificing functionality. Main component objects of data provider are:-

i) Connection:- It establishes a connection to a specified data source.

ii) Command:- It executes a command against a data source.

iii) DataReader:- It reads a forward-only, read-only stream of data from a data source.

iv) DataAdapter:- It populates a DataSet and resolves updates with the data source.

ii) XML: XML (Extensible Markup Language) is a text–based markup language that enables you to store data in a structured format by using meaningful tags. The term “extensible” implies that you can extend your ability to describe a document by defining meaningful tags for your application. XML is a cross-platform, hardware and software independent language. It enables computers to transfer data between heterogeneous systems. It is used as a common data interchange format in a number of applications. Some components of XML are: Processing Instruction, Tags, Elements, Contents, Attributes, Entities, and Comments.

7. Explain the following:

a) Automatic garbage collection

Ans: The garbage collector frees the application from the responsibility of freeing memory when no longer required. If sufficient memory is not available on the heap, then the garbage collection process is invoked. The garbage collection process begins after the JIT compilation and manages the allocation and deallocation of memory for an application. CLR calls garbage collector to handle memory efficiently.   

b) Structs    

Ans:

c) Working of foreach looping statement

Ans: The foreach statement is similar to for loop, but its implementation is different from for loop. foreach enables programmer to iterate the elements in arrays and collection classes such as List and HashTable.

 

Example:-  using System;

class test   {

public static void Main()   {

int [] arrayInt = {1, 2, 3, 4};

foreach ( int m in arrayInt)   {

Console .Write(“   “  + m);    }

Console.WriteLine (   );   }


d)Unsafe code

Ans: Unsafe code refers to the code that is processed with low security levels. There are situations where access to pointer types becomes a necessity. To address this need, C# provides the ability to write unsafe code. In unsafe code, it is possible to declare and operate on pointers, to perform conversions between pointers and integral types, to take the address of variables, and so forth. In a sense, it is like writing C code within a C# program. Unsafe code must be clearly marked with the modifier unsafe, so developers cannot possibly use unsafe features accidentally. When CLR finds this unsafe modifier, the execution engine works to ensure that the unsafe code cannot be executed in an untrusted environment. The unsafe features are only available in unsafe context.

b) Static constructors

Ans: A static constructor is a member that implements the actions required to initialize a class. Static constructors cannot have parameters, they cannot have accessibility modifiers, and they cannot be called explicitly. The static constructor for a class is called automatically.

Example:

 

class Employee

{

private static DataSet ds;

static Employee()

{

ds = new DataSet(…);

}

public string Name;

public decimal Salary;

}


         

f) Delegates

Ans: Delegates are objects that are used to call the methods of other objects. Delegates are said to be object-oriented function pointers since they allow a function to be invoked indirectly by using a reference to the function. 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. Example:

 

class Test  {

static void F()   {

System.Console.WriteLine(“Test.F”);    }

public static void Main()

{

SimpleDelegate dele = new SimpleDelegate(F);

dele();

}  }

 

c) JIT compiler

Ans:      

d) Abstract class

Ans:

Destructor

Ans:A destructor is a member that implements the actions required to destroy an instance of a class. Destructors cannot have parameters, they cannot have accessibility modifiers, and they cannot be called explicitly. The destructor of an instance is called automatically during garbage collection. Example:


using System;

class Point  {

public double x, y;

public Point(double x, double y){

this.x = x;

this.y = y;   }

~Point()  {

Console.WriteLine(“Destructed {0}”, this)  }

public override string ToString()    {

return string.Format(“({0}, {1})”, x, y);

}  }

 

The above example shows a Point class with a destructor.

17. Write a program to show the demonstration of ADO.NET?

A7) a) Explain ASP.NET architecture.

Ans:

11. Explain the method for passing argument in C#.

Ans:

ns ii) Inheritence

                                                 BASICS OF .NET

2. What is Meta data?

Ans:- The .NET framework makes language interoperation easier by allowing compiler to put additional information into all compiled modules and assemblies. This information is called Meta data. Metadata is binary information describing the program.

6. What is data provider?

Ans: A data provider is used for connecting to a database, executing commands, and retrieving information. A data provider is designed to be lightweight, creating a minimal layer between the data source and application code, increasing performance without sacrificing functionality. Main component objects of data provider are:- connection, command, DataReader, and DataAdapter.

7. What is exception?

Ans: An exception is any error condition or unexpected behavior encountered by a program in execution. Exception can be raised because of fault in our code or shared library or when operating system resources not being available and so on. Exception can be handled by using try block. In .NET exception is an object inherits from the ExceptionClass class.

8. What is backward compatibility?

Ans:- Backward compatibility is the strength of the Windows. It has one disadvantage. Whenever the new technology is introduced, the new sets of features are added to the Window API and its make the code and the design much more complex.

9. What is the use of attributes in C# program?

Ans: Attribute is declarative tag that is used to convey information to runtime about the behavior of programmatic element such as classes, enumeration and assemblies. Attributes are used for adding metadata. Attributes are applied to different element of the code. Attributes might require one or more parameter.

10. What is boxing and unboxing? Explain with an example.

Ans: Boxing:- The process of conversion of value type on the stack into object type  on the heap is called boxing. Ex: int m= 100;

object om = m;

Unboxing:- The conversion of object type on the heap back into value type on the stack is called unboxing. Ex:  int m=100;

Object om = m;

Int n = (int) om;

11. Explain uses of system collections class.

Ans: The System. Collections namespace contain s 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. Some namespace which are used are: ArrayList, BitArray, Comperer, DictionaryBase.

12. What is ASP.NET?

Ans: ASP.NET is a next generation ASP (Active Server Page). It is an entirely new paradigm for server-side ASP scripting. ASP.NET is a unified Web development platform that provides the services necessary for us to build enterprise Web application. It provides new programming model and infrastructure. It has been designed to work seamlessly with what you see Is what you get (WYSIWYG). Its syntax is very similar to ASP.

 

14. How the windows programming is different from. NET Programming?

Ans: Window Programming: In window programming the application programs call windows API functional directly. The application run in the windows environment means operating system. This type of application is called unmanaged or unsafe applications.

.NET Programming: In this programming the application program calls .Net Base Class library function that will communicate with operating system. The application run in .Net Runtime environment. This type of application is called safe application.

15. What is the importance of automatic memory management? Explain with example.

Ans: Automatic memory management increases the quality and enhances developer productivity without negative impact on either expressiveness or performance. It preserve the time of developer. Ex:

 

using System;

public class Stack  {

private Node first = null;

public bool Empty  {

get {

return (first == null);

}  }

public object Pop()   {

if (first == null)

Console.Write(“Can’t Pop from an empty Stack.”);

else {

object temp = first.Value;

first = first.Next;

return temp;

}  }

public void Push(object o)  {

first = new Node(o, first);   }

class Node   {

public Node Next;

public object Value;

public Node(object value):

this(value, null) {}

public Node(object value, Node next) {

Next = next;

Value = value;

}   }  }

In the above example, a Stack class is implemented as a linked list of Node instances. These node instances are created in the Push method and are deallocated when no longer in use.


 

21. With the help of an example differentiate struct and class.

Ans: Structs are similar to classes. But they are different in some ways:

i)Struct are value type while classes are reference type.

ii) A variable of struct type directly contains the data of the struct whereas a variable of a class type contains a reference to the object.

iii) Struct is useful for small data structure while classes are useful for both small and large data structure.

Leave a comment