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

MODEL EXAMINATION KEY

Sub. Title : C# and .NET Framework Date : 18.10.10


Sub. Code : CS1010 Branch : CSE
Time : 100 Minutes Max. Marks : 100

Part – A (5 x 2 = 10 Marks)
1. Define Versioning and Interoperability
- Making new versions of software modules work with the existing applications is known as
versioning. C# provides support for versioning with the help of new and override keywords.

2. Define boxing and Unboxing.


Unboxing is the process of converting object type back to the value type. We can only
unbox a variable that has been previously been boxed. Boxing is the reverse process of un
boxing the value type is converted into object type.

3. What is the difference between an indexer and a property?


The indexer takes an index argument and looks like an array

The indexer is declared using the name this

4. What is the use of ‘new’ in inheritance?


Using the new operator we can tell the compiler that the derived class method hides the base
class method.
5. What is DB Connection and DB Command?
The DBConnection object represents a connection to a data source. This connection
canbe shared among different command objects. The DBCommand object allows you to
send a command to the database. These objects are implicitly created when you create a
DataAdapter, but you can access these objects explicitly.

6. ADO.Net is disconnected data architecture. Justify?


The .NET framework provides a rich set of objects to manage database interaction.
]These classes are collectively referred to as ADO.NET. It typically connects to the
database toretrieve data, and connects again to update data. It provides a disconnected
subset of data for use,while reading and displaying. The key difference is that ADO.NET
is a disconnected data architecture.
7. Define WSDL.
WSDL is an XML schema used to describe the available methods -- the interface --
of a web service. You can see the WSDL document by appending ?WSDL to the web
service URL, http://localhost/WSCalc/Service1.asmx?wsdl
8. State the Difference between ASP and ASP.NET.
*ASP is interpreted, ASP.NET is compiled.
*Classic ASP uses a technology called ADO to connect and work with databases.
• ASP.NET uses the ADO.NET technology (which is the next generation of ADO).
9. Define intrinsic and custom attributes?
Attributes come in two flavors: intrinsic and custom .Intrinsic attributes are supplied as
part of the Common Language Runtime (CLR), and they are integrated into .NET.
Custom attributes are attributes you create for your own purposes. Most programmers
will use only intrinsic attributes, though custom attributes can be a powerful tool when
combined with reflection
10. Define Singleton and single Call in remoting?
Well-known objects come in two varieties:
1.singleton and 2. single-call.
• With a well-known singleton object, all messages for the object, from all clients, are
dispatched to a single object running on the server.
With a well-known single-call object, each new message from a client is handled by a
new object.

Part – B ((2*16 = 32 & 1*8 = 8):: 40 Marks)


11 .a) i ) Explain the architecture of .Net framework with neat diagram(8)

.NETe
ii) Explain the different types of operators supported in C#(8)
An operator is a symbol that tells the computer to perform certain mathematical or logical
manipulations.
C sharp operators can be classified into a number of related categories
1. Arithmetic operators 2. Relational operators 3.Logical operators
4.Assignment operators 5.Increment and Decrement 6. Conditional
7.Bitwise and 8.Special operators(is,as,typeof, sizeof, new,.(dot),checked,unchecked)
(Or)
b) i) What is type conversion. Explain the different types of type conversion?(8)
Converting of one data type into other data type is called type conversion.
Types of conversations:
• Implicit type conversions: (Arithmetic operations)- no loss of data-
• Explicit type conversions:(Casting operations)-loss of data

ii) What is an array list. Write a program to sort and reverse of an array using methods(8)
using System;
namespace arrayclass
{
class SortReverse
{
static void Main(string[] args)
{
int[] x = {30, 10, 80, 90, 20};
Console.WriteLine("Array before Sorting");
foreach(int i in x)
Console.WriteLine("" +i);
Console.WriteLine();
Array.Sort(x);
Console.WriteLine("SORTED ARRAY");
foreach(int i in x)
Console.WriteLine(" "+i);
Console.WriteLine();
Array.Reverse(x);
Console.WriteLine("reversed contents");
foreach (int i in x)
Console.WriteLine(" " + i);
Console.WriteLine();
x.SetValue(25, 1);
Console.WriteLine("the values are");
foreach (int i in x)
Console.WriteLine(" " + i);
Console.WriteLine();
}
}
}
12 a) i) Explain different types of constructors in C#(10)
C# supports a special type of method, called a constructor that enables an object to initialize
itself when it is created. Constructor has the name as class itself. They don’t not specify the
return type , not even void. Constructors are usually public because they are provided to create
objects
Types:
• Copy constructors
• Private constructor
• Static constructor
• Over loaded constructor

ii) Write a program to add two complex numbers using operator overloading(6)
using System;
class Complex
{
double x;
double y;
public Complex()
{
}
public Complex(double real,double imag)
{
x=real;
y=imag;
}
public static Complex operator + (Complex c1,Complex c2)
{
Complex c3=new Complex();
c3.x=c1.x+c2.x;
c3.y=c1.y+c2.y;
return(c3);
}
public void display()
{
Console.Write(x);
Console.Write("+j" +y);
Console.WriteLine();
}
}
class ComplexTest
{
public static void Main()
{
Complex a,b,c;
a=new Complex(2.5,3.5);
b=new Complex(1.6,2.7);
c=a+b;
Console.Write("a=");
a.display();
Console.Write("b=");
b.display();
Console.Write("c=");
c.display();
}
}
(Or)
b)i) Write the necessary steps to create and use delegates(8)
A delegate object is a special type of object that contains the details of a method rather
than data. Delegates in c # are used for two purposes: Call back and Event handling
the steps involved in creating and using delegates
*Delegate declaration
*Delegate methods definition
*Delegate instantiation
*Delegate invocation
ii) Define Exception handling. Explain the mechanism to handle exceptions(8)
An Exception is a condition that is caused by run time error in the program. When the C
# compile encounters an error such as dividing an integer by zero, it creates an
exception object and throws it
Common C# exceptions:
1 SystemException
2.AccessException
3.ArgumentException
Mechanisms to handle exceptions:
*Find the problem
*Inform that an error has occurred
*Receive the error information
*take corrective actions.
13 a i) Write a windows program to estimate the price of the computer(8)

CODING :

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;

namespace ComputerPriceEstimator
{

public class MainForm : System.Windows.Forms.Form


{

private System.ComponentModel.Container components = null;

public MainForm()
{

InitializeComponent();
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void btnCalculate_Click(object sender, System.EventArgs e)
{
decimal basePrice = 200;
string strBase = string.Format("Base: {0:C}", basePrice);
Debug.WriteLine(strBase);

// CPU
decimal cpuPrice;
if (rdoIntel22.Checked)
cpuPrice = 125;
else if (rdoIntel26.Checked)
cpuPrice = 160;
else
cpuPrice = 165;
string strCpu = string.Format("CPU: {0:C}", cpuPrice);
Debug.WriteLine(strCpu);
basePrice += cpuPrice;

// Memory
decimal memPrice;
if (rdo128MB.Checked)
memPrice = 55;
else if (rdo256MB.Checked)
memPrice = 75;
else
memPrice = 120;
string strMem = string.Format("Memory: {0:C}", memPrice);
Debug.WriteLine(strMem);
basePrice += memPrice;

// DISK
decimal diskPrice;
if (rdo40GB.Checked)
diskPrice = 125;
else if (rdo60GB.Checked)
diskPrice = 140;
else
diskPrice = 200;
string strDisk = string.Format("Disk: {0:C}", diskPrice);
Debug.WriteLine(strDisk);
basePrice += diskPrice;

// Fax/Modem
decimal faxPrice = 0;
if (chkFaxModem.Checked)
faxPrice += 45;
string strFax = string.Format("Fax/Modem: {0:C}", faxPrice);
Debug.WriteLine(strFax);
basePrice += faxPrice;

// Wireless NIC
decimal nicPrice = 0;
if (chkWirelessNIC.Checked)
nicPrice += 75;
string strNic = string.Format("Wireless NIC: {0:C}", nicPrice);
Debug.WriteLine(strNic);
basePrice += nicPrice;

// Floppy
decimal floppyPrice = 0;
if (chkFloppy.Checked)
floppyPrice += 30;
string strFloppy = string.Format("Floppy: {0:C}", floppyPrice);
Debug.WriteLine(strFloppy);
basePrice += floppyPrice;

string strTotal = string.Format("Total: {0:C}", basePrice);


Debug.WriteLine(strTotal);
lblCalculatedValue.Text = strTotal;
}
}
}

ii) Explain about ADO.NET Object Model(8)


The ADO.NET object model is rich, but at its heart it is a fairly straightforward set of classes.
The most important of these is the DataSet.

DATA SET:
The DataSet represents a subset of the entire database, cached on your machine without a
continuous connection to the database.
DATATABLES AND DATACOLUMNS:

The DataTable can be created programmatically or as a result of a query against the


database. The DataTable has a number of public properties, including the Columns collection,
which returns the DataColumnCollection object, which in turn consists of DataColumn objects.
Each DataColumn object represents a column in a table

DATARELATIONS:

In addition to the Tables collection, the DataSet has a Relations property, which returns a
DataRelationCollection consisting of DataRelation objects. Each DataRelation represents a
relationship between two tables through DataColumn objects.

ROWS:
DataTable's Rows collection returns a set of rows for any given table.

DATA ADAPTER:
The DataSet is an abstraction of a relational database. ADO.NET uses a DataAdapter as a
bridge between the DataSet and the data source, which is the underlying database.
DataAdapter provides the Fill ( ) method to retrieve data from the database and populate the
DataSet.
DBCOMMAND AND DBCONNECTION:
The DBConnection object represents a connection to a data source. This connection can
be shared among different command objects.

THE DATAADAPTER OBJECT:


Rather than tie the DataSet object too closely to your database architecture, ADO.NET
uses a DataAdapter object to mediate between the DataSet object and the database.
(Or)
b)i) Write a database windows application to display the details of the employee using data
bound control
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace ProgrammingCSharpWindows.Form
{
public class ADOForm3 : System.Windows.Forms.Form
{
private System.ComponentModel.Container components;
private System.Windows.Forms.DataGrid
CustomerDataGrid; //name of the grid control
public ADOForm3( )
{
InitializeComponent( );
// set up connection and command strings
string connectionString = "server=(local)\\NetSDK;" +"Trusted_Connection=yes;
database=northwind";
string commandString ="Select CompanyName, ContactName, ContactTitle, "
+ "Phone, Fax from Customers";
// create a data set and fill it
SqlDataAdapter DataAdapter =new SqlDataAdapter(commandString, connectionString);
DataSet DataSet = new DataSet( );
DataAdapter.Fill(DataSet,"Customers");
// bind the DataSet to the grid
CustomerDataGrid.DataSource=DataSet.Tables["Customers"].DefaultView;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components == null)
{
components.Dispose( );
}
}
base.Dispose(disposing);
}
private void InitializeComponent( )
{
this.components =new System.ComponentModel.Container ( );
this.CustomerDataGrid =
new System.Windows.Forms.DataGrid ( );
CustomerDataGrid.BeginInit ( );
CustomerDataGrid.Location =
new System.Drawing.Point (8, 24);
CustomerDataGrid.Size =new System.Drawing.Size (656, 224);
CustomerDataGrid.DataMember = " ";
CustomerDataGrid.TabIndex = 0;
CustomerDataGrid.Navigate +=
new System.Windows.Forms.NavigateEventHandler
(this.dataGrid1_Navigate);
this.Text = "Using the Data Grid";
this.AutoScaleBaseSize =
new System.Drawing.Size (5, 13);
this.ClientSize = new System.Drawing.Size (672, 273);
this.Controls.Add (this.CustomerDataGrid);
CustomerDataGrid.EndInit ( );
}
protected void dataGrid1_Navigate
(object sender, System.Windows.Forms.NavigateEventArgs ne)
{
}
public static void Main(string[] args)
{ CustomerDataGrid.DataSource=DataSet.Tables["Customers"].DefaultView;

Application.Run(new ADOForm3( ));


}
}
}

Notice that every field in the record is represented by a column in the DataGrid, and that the
titles of the columns are the names of the fields. All of this is the default behavior of the
DataGrid.
ii) List out the categories of controls used in windows based applications and explains the
importance of each components
• All windows forms
• Common controls
• Containers
• Menus and tool bars
• data
• Components
• Printing
• Dialogs
• WPF interoperability
• Reporting
• Visual Basic PowerPacks
• General
14a i) Explain the web form life cycle in details(6)

Initialize,
Load ViewState,
Process Postback Data,
Load,
Send Postback Change Modifications,
Handle Postback Events,
PreRender,
Save State,
Render,
Dispose

ii) Write the web based application for online shopping(10)


The complete HTML for the .aspx file.
The .aspx file
<%@ Page language="c#"
Codebehind="HelloWeb.aspx.cs"
AutoEventWireup="false"
Inherits="ProgrammingCSharpWeb.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR"
Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript"
content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="Label1"
style="Z-INDEX: 101; LEFT: 20px; POSITION: absolute; TOP: 28px"
runat="server">Welcome to NorthWind.</asp:Label>
<asp:Label id="Label2"
style="Z-INDEX: 102; LEFT: 20px; POSITION: absolute; TOP: 67px"
runat="server">Your Name:</asp:Label>
<asp:Label id="Label3"
style="Z-INDEX: 103; LEFT: 20px; POSITION: absolute; TOP: 134px"
runat="server">Shipper:</asp:Label>
<asp:Label id="lblFeedBack"
style="Z-INDEX: 104; LEFT: 20px; POSITION: absolute; TOP: 241px"
runat="server">Please choose the shipper.</asp:Label>
<asp:Button id="Order"
style="Z-INDEX: 105; LEFT: 20px; POSITION: absolute; TOP: 197px"
runat="server" Text="Order"></asp:Button>
<asp:Button id="Cancel"
style="Z-INDEX: 106; LEFT: 128px; POSITION: absolute; TOP: 197px"
runat="server" Text="Cancel"></asp:Button>
<asp:TextBox id="txtName"
style="Z-INDEX: 107; LEFT: 128px; POSITION: absolute; TOP: 64px"
runat="server"></asp:TextBox>
<asp:RadioButtonList id="rbl1"
style="Z-INDEX: 108; LEFT: 112px; POSITION: absolute; TOP: 130px"
runat="server"></asp:RadioButtonList>
</form>
</body>
</HTML>
• The <asp:Button> controls will be converted into a standard HTML <input> tag. Again,
the advantage of using ASP controls is that they provide a more consistent object model
for the programmer and yet they generate standard HTML that every browser can
display. Because they are marked with the runat=Server attribute as well as given an id
attribute, you can access these buttons programmatically in server-side code if you
choose to do so.

THE CODE-BEHIND PAGE SUPPORTING THE HTML


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace ProgrammingCSharpWeb
{
// page constructor
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label lblFeedBack;
protected System.Web.UI.WebControls.Button Order;
protected System.Web.UI.WebControls.Button Cancel;
protected System.Web.UI.WebControls.TextBox txtName;
protected System.Web.UI.WebControls.RadioButtonList rbl1;
private System.Data.SqlClient.SqlConnection myConnection;
private System.Data.DataSet myDataSet;
private System.Data.SqlClient.SqlCommand myCommand;
private System.Data.SqlClient.SqlDataAdapter dataAdapter;
private void Page_Load(object sender, System.EventArgs e)
{
// the first time we load the page, get the data and
// set the radio buttons
if (!IsPostBack)
{
string connectionString = "server=(local)\\NetSDK;" +"Trusted_Connection=yes;
database=northwind";
myConnection = new System.Data.SqlClient.SqlConnection(connectionString);
myConnection.Open( );
// create the data set and set a property
myDataSet = new System.Data.DataSet( );
myDataSet.CaseSensitive=true;
// create the SqlCommand object and assign the
// connection and the select statement
myCommand = new System.Data.SqlClient.SqlCommand( );
myCommand.Connection=myConnection;
myCommand.CommandText =
"Select ShipperID, CompanyName from Shippers";
// create the dataAdapter object and pass in the
// SqlCommand object and establish the data mappings
dataAdapter = new System.Data.SqlClient.SqlDataAdapter( );
dataAdapter.SelectCommand= myCommand;
dataAdapter.TableMappings.Add("Table","Shippers");
// Tell the dataAdapter object to fill the dataSet
dataAdapter.Fill(myDataSet);
// set up the properties for the RadioButtonList
rbl1.RepeatLayout =
System.Web.UI.WebControls.RepeatLayout.Flow;
rbl1.DataTextField = "CompanyName";
rbl1.DataValueField = "ShipperID";
// set the data source and bind to i
rbl1.DataSource = myDataSet.Tables["Shippers"].DefaultView;
rbl1.DataBind( );
// select the first button
rbl1.Items[0].Selected = true;
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by
// the ASP.NET Web Form Designer.
//
InitializeComponent( );
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent( )
{
this.Order.Click += new System.EventHandler(this.Order_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Order_Click(object sender, System.EventArgs e)
{
// create the message by getting
// the values from the controls
string msg;
msg = "Thank you " + txtName.Text +". You chose " ;
// iterate over the radio buttons
for (int i = 0;i<rbl1.Items.Count;i++)
{
// if it is selected, add it to the msg.
if (rbl1.Items[i].Selected)
{
msg = msg + rbl1.Items[i].Text;
lblFeedBack.Text = msg;
} // end if selected
} // end for loop
} // end Order_Click
} // end class WebForm1
} // end namespace ProgrammingCSharpWeb
(Or)
b) Write a web service program for calculator and write the necessary steps to invoke the
methods(16)
CALCULATOR WEB SERVICE PROGRAM
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace WebService3
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment
the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{

[WebMethod]
public double Add(double x, double y)
{
return x+y;
}
[WebMethod]
public double Sub(double x, double y)
{
return x-y;
}
[WebMethod]
public double Mult(double x, double y)
{
return x*y;
}
[WebMethod]
public double Div(double x, double y)
{
return x/y;
}
[WebMethod]
public double Pow(double x, double y)
{
double retVal = x;
for (int i = 0;i < y-1;i++)
{
retVal *= x;
}
return retVal;
}
}
}
15 a) i) Explain about Assemblies in detail (8)
• An assembly is a collection of files that appears to the user to be a single dynamic link
library (DLL) or executable (EXE). DLLs are collections of classes and methods that are
linked into your running program only when they are needed.
• Multi-Module Assemblies
• An assembly is loaded into its application by the AssemblyResolver through a process called
probing. The assembly resolver is called by the .NET Framework automatically; you do
not call it explicitly. Its job is to resolve the assembly name to an EXE program and load
your program.
TYPES OF ASSEMBLIES:
Assemblies come in two flavors: private and shared

Private Assemblies.
Private assemblies are intended to be used by only one application; shared assemblies are
intended to be shared among many applications
Shared Assemblies
• You can create assemblies that can be shared by other applications. You might want to do
this if you have written a generic control or a class that might be used by other
developers. If you want to share your assembly, it must meet certain stringent
requirements.
• First, your assembly must have a strong name. Strong names are globally unique.
• Second, your shared assembly must be protected against newer versions trampling over
it, and so it must have version control.
• Finally, to share your assembly, place it in the Global Assembly Cache (GAC)
(pronounced GACK). This is an area of the filesystem set aside by the Common
Language Runtime (CLR) to hold shared assemblies.
ii) What is marshalling and explain its importance (8)
The process of preparing an object to be remoted is called marshaling. On a single machine,
objects might need to be marshaled across context, app domain, or process boundaries.
• Application Domains
• Creating and Using App Domains:
• Marshaling Across App Domain Boundaries:
• Understanding marshaling with proxies:
• Specifying the marshaling method:
• Marshaling across app domain boundaries
• Marshaling Across Context Boundaries

(Or)
b i) What is Remoting ? Explain the necessary steps to access remote methods (8)
When an object is marshaled, either by value or by proxy, across a process or machine boundary,
it is said to be remoted
steps:
• create interface program
• building the server
• creating the server program
• building the client
• creating the client program
ii) Explain the threading concepts in C#
Threads are relatively lightweight processes responsible for multitasking within a single
application. The System.Threading namespace provides a wealth of classes and interfaces to
manage multithreaded programming.
Starting Threads
Thread myThread = new Thread( new ThreadStart(myFunc) );
Joining Threads
To join thread 1 (t1) onto thread 2 (t2), write:
t2.Join( );
Suspending Threads
Killing Threads

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