Set - 9

Question 1 :

How can you debug failed assembly binds?

Answer :

Use the Assembly Binding Log Viewer (fuslogvw.exe) to find out the paths searched.


Question 2 :

Where are shared assemblies stored?

Answer :

Global assembly cache.


Question 3 :

How can you create a strong name for a .NET assembly?

Answer :

With the help of Strong Name tool (sn.exe).


Question 4 :

Where's global assembly cache located on the system?

Answer :

Usually C:\winnt\assembly or C:\windows\assembly.


Question 5 :

Can you have two files with the same file name in GAC?

Answer :

Yes, remember that GAC is a very special folder, and while normally you would not be able to place two files with the same name into a Windows folder, GAC differentiates by version number as well, so it's possible for MyApp.dll and MyApp.dll to co-exist in GAC if the first one is version 1.0.0.0 and the second one is 1.1.0.0.
So let's say I have an application that uses MyApp.dll assembly, version 1.0.0.0. There is a security bug in that assembly, and I publish the patch, issuing it under name MyApp.dll 1.1.0.0. How do I tell the client applications that are already installed to start using this new MyApp.dll?
Use publisher policy. To configure a publisher policy, use the publisher policy configuration file, which uses a format similar app .config file. But unlike the app .config file, a publisher policy file needs to be compiled into an assembly and placed in the GAC.


Question 6 :

What is delay signing?

Answer :

Delay signing allows you to place a shared assembly in the GAC by signing the assembly with just the public key. This allows the assembly to be signed with the private key at a later stage, when the development process is complete and the component or assembly is ready to be deployed. This process enables developers to work with shared assemblies as if they were strongly named, and it secures the private key of the signature from being accessed at different stages of development.


Question 7 :

What is a "Virtual Directory"? 

Answer :

Virtual directories are aliases for directory paths on the server. It allows moving files on the disk between different folders, drives or even servers without changing the structure of web pages. It avoids typing an extremely long URL each time to access an ASP page.


Question 8 :

Give the comment Tags for the following? 

Answer :

VBScript : REM & '(apostrophe)
JavaScript : // (single line comment)
/* */ (Multi-line comments)


Question 9 :

What is the command to display characters to the HTML page?

Answer :

Response.Write

 


Question 10 :

What is Extranet? 

Answer :

An area of a web site available only to a set of registered visitors.

< SCRIPT LANGUAGE="VBScript" RUNAT=Server >a = 1< /SCRIPT >
< SCRIPT LANGUAGE="VBScript" >a = 2< /SCRIPT >
< %Response.Write a% >

In the sample code shown above, what will be written to the screen? 

A. 1
B. 2
C. 1, 2
D. 1&2
E. Nothing. 

Explanation :

Answer : E


Question 11 :

< % iPos = Instr("Hello World","r") % >

Referring to the above, what is the value of iPos? 
A. 0
B. 1
C. 2
D. 8
E. 9

Answer :

Answer: E


Question 12 :

What are the tags necessary to be present within the <FORM > tag? 

Answer :

tag: Provides input spaces (text boxes, combo boxes, radio button, etc.) on a form called fields. It has three attributes TYPE, NAME and VALUE. TYPE provides the characteristics of the field and the NAME specifies a name to the field by which it can be referred.


Question 13 :

How do you create a recordset object in VBScript?

Answer :

Answer1 
//First of all declare a variable to hold the Recordset object, ex- 
Dim objRs 
//Now, Create this varible as a Recordset object, ex-

Set objRs=Server.CreateObject(ADODB.RECORDSET) 

Answer2 

" rs.MoveNext
wend
end if
%'>

*. Create Recordset object
*. Place form field value in a variable named "param"
*. Define query by concatenating strings and variable value
*. Open RecordSet Object. Note that the first parameter is the Command Text. The second parameter is the Connection String. The Command Object and Connection Object are created implicitly.
*. Make sure the RecordSet isn't empty
*. Begin executing a loop which goes through all records in the RecordSet.
*. Write each record's "firstname" and "lastname" fields to the page on a separate line.
*. Move to Next Record.


Question 14 :

How do you get the value of a combo box in Javascript?

Answer :

Answer1.

document.forms['formName'].elements['comboName'].options[i].value

Answer2.

document.form_name.element_name.value


Question 15 :

What is the base class of Button control? 

Answer :

Listing from visual studio .net > Button Class

System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.ButtonBase
System.Windows.Forms.Button


Question 16 :

Which DLL translate XML to SQL in IIS? 

Answer :

Sqlisapi.dll


Question 17 :

What is the Differnce Between Response.write & response.output.Write

Answer :

In ASP.NET the Response object is of type HttpResponse and when you say Response.Write you're really saying (basically) HttpContext.Current.Response.Write and calling one of the many overloaded Write methods of HttpResponse. 
Response.Write then calls .Write() on it's internal TextWriter object: 

public void Write(object obj){ this._writer.Write(obj);}

HttpResponse also has a Property called Output that is of type, yes, TextWriter, so:

public TextWriter get_Output(){ return this._writer; } 

Which means you can to the Response whatever a TextWriter will let you. Now, TextWriters support a Write() method ala String.Format, so you can do this:

Response.Output.Write("Scott is {0} at {1:d}", "cool",DateTime.Now); 

But internally, of course, this this is happening:

public virtual void Write(string format, params object[] arg){
	this.Write(string.Format(format, arg));
}


Question 18 :

Which dll is required to translate XML to SQL in IIS ? 

Answer :

Microsoft.data.sqlxml.dll


Question 19 :

What should one do to make class serializable? 

Answer :

Answers1:
To make a class serializable is to mark it with the Serializable attribute as follows.

[Serializable]
public class MyObject {
    public int n1 = 0;
    public int n2 = 0;
    public String str = null;
}


Question 20 :

How is a property designated as read-only? 

Answer :

In VB.NET:
Public ReadOnly Property PropertyName As ReturnType
Get 'Your Property Implementation goes in here
End Get
End Property

in C#

public returntype PropertyName{
    get{
    //property implementation goes here
    }
    // Do not write the set implementation
}


Question 21 :

What is the difference between a.Equals(b) and a == b?

Answer :

Answer1:
a=b is used for assigning the values (rather then comparison) and a==b is for comparison. 

Answer2:
a == b is used to compare the references of two objects 
a.Equals(b) is used to compare two objects 

Answer3:
A equals b -> copies contents of b to a
a == b -> checks if a is equal to b 

Answer4:
Equals method compares both type and value of the variable, while == compares value. 
int a = 0;
bool b = 0

if(a.Equals(b)) 

Answer5:
a.Equals(b) checks whether the Type of a is equal to b or not! Put it in another way,
Dim a As Integer = 1
Dim b As Single = 1

a.Equals(b) returns false. The Equals method returns a boolean value. 
a == b is a simple assignment statement. 

Answer6:
a.equals(b) will check whether the "b" has same type as "a" has and also has the same data as "a" has. 
a==b will do the same thing. 
if you have done this in c++ under "operator overloading" than you guys must be aware of this sytaxts. they are doing the same thing there is only sytaxtical difference. 
let me explain it in different manner.
a==b : means compare "b" with "a". always left hand side expression evaluated first so here in this case "a" (considered an object) will call the overloaded operator "=" which defines "Equals(object)" method in it's class. thus, ultimately a.equals(b) goanna called. 
so the answer is: both will perform the same task. they are different by syntaxt 

Answer7:
Difference b/w a==b,a.Equals(b)
a.Equals(b):
The default implementation of Equals supports reference equality only, but derived classes can override this method to support value equality. 

For reference types, equality is defined as object equality; that is, whether the references refer to the same object. For value types, equality is defined as bitwise equality
== :
For predefined value types, the equality operator (==) returns true if the values of its operands are equal, false otherwise. For reference types other than string, == returns true if its two operands refer to the same object. For the string type, == compares the values of the strings.


Question 22 :

Using ActiveX Control in .Net ?

Answer :

ActiveX control is a special type of COM component that supports a User Interface. Using ActiveX Control in your .Net Project is even easier than using COM component. They are bundled usually in .ocx files. Again a proxy assembly is made by .Net utility AxImp.exe (which we will see shortly) which your application (or client) uses as if it is a .Net control or assembly. 

Making Proxy Assembly For ActiveX Control: First, a proxy assembly is made using AxImp.exe (acronym for ActiveX Import) by writing following command on Command Prompt: 

C:> AxImp C:MyProjectsMyControl.ocx
This command will make two dlls, e.g., in case of above command 

MyControl.dll
AxMyControl.dll
The first file MyControl.dll is a .Net assembly proxy, which allows you to reference the ActiveX as if it were non-graphical object. 

The second file AxMyControl.dll is the Windows Control, which allows u to use the graphical aspects of activex control and use it in the Windows Form Project. 

Adding Reference of ActiveX Proxy Assembly in your Project Settings: To add a reference of ActiveX Proxy Assembly in our Project, do this: 

o Select Project A Add Reference (Select Add Reference from Project Menu).
o This will show you a dialog box, select .Net tab from the top of window.
o Click Browse button on the top right of window.
o Select the dll file for your ActiveX Proxy Assembly (which is MyControl.dll) and click OK o Your selected component is now shown in the 'Selected Component' List Box. Click OK again Some More On Using COM or ActiveX in .Net


.Net only provides wrapper class or proxy assembly (Runtime Callable Wrapper or RCW) for COM or activeX control. In the background, it is actually delegating the tasks to the original COM, so it does not convert your COM/activeX but just imports them. 

A good thing about .Net is that when it imports a component, it also imports the components that are publically referenced by that component. So, if your component, say MyDataAcsess.dll references ADODB.dll then .Net will automatically import that COM component too! 

The Visual Studio.NET does surprise you in a great deal when u see that it is applying its intellisense (showing methods, classes, interfaces, properties when placing dot) even on your imported COM components!!!! Isn't it a magic or what? 

When accessing thru RCW, .Net client has no knowledge that it is using COM component, it is presented just as another C# assembly. 

U can also import COM component thru command prompt (for reference see Professional C# by Wrox) 

U can also use your .Net components in COM, i.e., export your .net components (for reference see Professional C# by Wrox)


Question 23 :

What is the difference between VB and VB.NET?

Answer :

Now VB.NET is object-oriented language. The following are some of the differences: 

Data Type Changes 
The .NET platform provides Common Type System to all the supported languages. This means that all the languages must support the same data types as enforced by common language runtime. This eliminates data type incompatibilities between various languages. For example on the 32-bit Windows platform, the integer data type takes 4 bytes in languages like C++ whereas in VB it takes 2 bytes. Following are the main changes related to data types in VB.NET: 

. Under .NET the integer data type in VB.NET is also 4 bytes in size.
. VB.NET has no currency data type. Instead it provides decimal as a replacement.
. VB.NET introduces a new data type called Char. The char data type takes 2 bytes and can store Unicode characters.
. VB.NET do not have Variant data type. To achieve a result similar to variant type you can use Object data type. (Since every thing in .NET including primitive data types is an object, a variable of object type can point to any data type).
. In VB.NET there is no concept of fixed length strings.
. In VB6 we used the Type keyword to declare our user-defined structures. VB.NET introduces the structure keyword for the same purpose.
Declaring Variables
Consider this simple example in VB6:
Dim x,y as integer

In this example VB6 will consider x as variant and y as integer, which is somewhat odd behavior. VB.NET corrects this problem, creating both x and y as integers. 

Furthermore, VB.NET allows you to assign initial values to the variables in the declaration statement itself: 
br> Dim str1 as string = Hello 

VB.NET also introduces Read-Only variables. Unlike constants Read-Only variables can be declared without initialization but once you assign a value to it, it cannot be changes. 

Initialization here
Dim readonly x as integer
In later code
X=100
Now x can't be changed
X=200 *********** Error **********
Property Syntax
In VB.NET, we anymore don't have separate declarations for Get and Set/Let. Now, everything is done in a single property declaration. This can be better explained by the following example.
Public [ReadOnly | WriteOnly] Property PropertyName as Datatype
Get
Return m_var
End Get
Set
M_var = value
End Set
End Property
Example:
Private _message as String
Public Property Message As String
Get
Return _message
End Get
Set
_message = Value
End Set
End Property

ByVal is the default - This is a crucial difference betwen VB 6.0 and VB.NET, where the default in VB 6.0 was by reference. But objects are still passed by reference. 

Invoking Subroutines In previous versions of VB, only functions required the use of parentheses around the parameter list. But in VB.NET all function or subroutine calls require parentheses around the parameter list. This also applies, even though the parameter list is empty. 

User-Defined Types - VB.NET does away with the keyword Type and replaces it with the keyword Structure
Public Structure Student
Dim strName as String
Dim strAge as Short
End Structure
Procedures and Functions

In VB6 all the procedure parameters are passed by reference (ByRef) by default. In VB.NET they are passed by value (ByVal) by default. Parantheses are required for calling procedures and functions whether they accept any parameters or not. In VB6 functions returned values using syntax like: FuntionName = return_value. In VB.NET you can use the Return keyword (Return return_value) to return values or you can continue to use the older syntax, which is still valid.

Scoping VB.NET now supports block-level scoping of variables. If your programs declare all of the variables at the beginning of the function or subroutine, this will not be a problem. However, the following VB 6.0 will cause an issue while upgrading to VB .NET 

Do While objRs.Eof
Dim J as Integer
J=0
If objRs("flag")="Y" then
J=1
End If
objRs.MoveNext
Wend
If J Then
Msgbox "Flag is Y"
End If

In the above example the variable J will become out of scope just after the loop, since J was declared inside the While loop. 

Exception Handling 

The most wanted feature in earlier versions of VB was its error handling mechanism. The older versions relied on error handlers such as "On Error GoTo and On Error Resume Next. VB.NET provides us with a more stuructured approach. The new block structure allows us to track the exact error at the right time. The new error handling mechanism is refered to as Try...Throw...Catch...Finally. The following example will explain this new feature. 

Sub myOpenFile()
Try
Open "myFile" For Output As #1
Write #1, myOutput
Catch
Kill "myFile"
Finally
Close #1
End try
End Sub

The keyword SET is gone - Since everything in VB.NET is an object. So the keyword SET is not at all used to differentiate between a simple variable assignment and an object assignment. So, if you have the following statement in VB 6.0 

Set ObjConn = Nothing
Should be replaced as
ObjConn = Nothing.
Constructor and Destructor

The constructor procedure is one of the many new object-oriented features of VB.NET. The constructor in VB.NET replaces the Class_Initialize in VB 6.0. All occurance of Class_Initialize in previous versions of VB should now be placed in a class constructor. In VB.NET, a constructor is added to a class by adding a procedure called New. We can also create a class destructor, which is equivalent to Class_Terminate event in VB 6.0, by adding a sub-procedure called Finalize to our class. Usage of Return In VB.NET, we can use the keyword return to return a value from any function. In previous versions, we used to assign the value back with the help of the function name itself. The following example explains this: 

Public Function Sum (intNum1 as Integer, intNum2 as Integer) as Integer
Dim intSum as Integer
intSum = intNum1 + intNum2
Return intSum
End Function
Static Methods

VB.NET now allows you to create static methods in your classes. Static methods are methods that can be called without requiring the developer to create instance of the class. For example, if you had a class named Foo with the non-static method NonStatic() and the static method Static(), you could call the Static() method like so: 

Foo.Static()

However, non-static methods require than an instance of the class be created, like so: 

Create an instance of the Foo class
Dim objFoo as New Foo()
Execute the NonStatic() method
ObjFoo.NonStatic()

To create a static method in a VB.NET, simply prefix the method definition with the keyword Shared.


Question 24 :

I am constantly writing the drawing procedures with System.Drawing.Graphics, but having to use the try and dispose blocks is too time-consuming with Graphics objects. Can I automate this? 

Answer :

Yes, the code

System.Drawing.Graphics canvas = new System.Drawing.Graphics();
try{
    //some code
}
finally

canvas.Dispose();

is functionally equivalent to

using (System.Drawing.Graphics canvas = new System.Drawing.Graphics())
{
    //some code
} //canvas.Dispose() gets called automatically


Question 25 :

What's the use of System.Diagnostics.Process class? 

Answer :

By using System.Diagnostics.Process class, we can provide access to the files which are presented in the local and remote system. 
Example: System.Diagnostics.Process("c:\mlaks\example.txt") — local file
System.Diagnostics.Process("http://www.mlaks.com\example.txt") — remote file


Question 26 :

How do you get records number from 5 to 15 in a dataset of 100 records? Write code. 

Answer :

Answer1

DataSet ds1=new DataSet(); String strCon="data source=IBM-6BC8A0DACEF;initial catalog=pubs;integrated security=SSPI;persist" +" security info=False;user 
id=sa;workstation id=IBM-6BC8A0DACEF;packet size=4096?;

String strCom1="SELECT * FROM employee";
SqlDataAdapter sqlDa1=new SqlDataAdapter(strCom1,strCon);
ds1.Tables.Add("employee");
sqlDa1.Fill(ds1,40,50,ds1.Tables["employee"].TableName);
DataGrid dg1.DataSource=ds1.Tables["employee"].DefaultView;
dg1.DataBind();

Answer2

OleDbConnection1.Open()
OleDbDataAdapter1.Fill(DataSet21, 5, 15, "tab")

This will fill the dataset with the records starting at 5 to 15


Question 27 :

How do you call and execute a Stored Procedure in .NET? Give an example. 

Answer :

Answer1

ds1=new DataSet();

sqlCon1=new SqlConnection(connectionstring);

String strCom1="byroyalty";

sqlCom1=new SqlCommand(strCom1,sqlCon1);
sqlCom1.CommandType=CommandType.StoredProcedure;
sqlDa1=new SqlDataAdapter(sqlCom1);
SqlParameter myPar=new SqlParameter("@percentage",SqlDbType.Int);
sqlCom1.Parameters.Add (myPar);
myPar.Value=40;
sqlDa1.Fill(ds1);
dg1.DataSource=ds1;
dg1.DataBind(); 

Answer2

Yes

Dim cn as new OleDbConnection ( "Provider=Microsoft.Jet.OLEDB.4.0;"+ _
"Data Source=C:\Documents and Settings\User\My Documents\Visual Studio Projects\1209\db1.mdb"+ _
"User ID=Admin;"+ _
"Password=;");
Dim cmd As New OleDbCommand("Products", cn)
cmd.CommandType = CommandType.StoredProcedure

Dim da As New OleDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds, "Products")
DataGrid1.DataSource = ds.Tables("Products") 


Question 28 :

How do u call and execute a stored procedure in .NET? 

Answer :

system.Data;
system.Data.SqlClient;

SqlConnection sqCon = new SqlConnection("connection string");
SqlCommand sqCmd = new SqCmd();
sqCmd.Connection = sqCon;
sqCmd.CommandText = procedure_name;
sqCmd.CommandType = CommandType.StoredProcedure;
sqComd.ExecuteReader();


Question 29 :

How do you create thread in .NET?

Answer :

1) Import System.Threading
2) Create a new thread using new Thread() and assign the address of the method
3) Use Thread.Start method to start the execution

using System;
using System.Threading;
public class Test{
	static void Main(){
		ThreadStart job = new ThreadStart(ThreadJob);
		Thread thread = new Thread(job);
		thread.Start();
		....
	}
}


Question 30 :

What is the output for the following code snippet:

public class testClass{
	public static void Main(string[] args){
		System.Console.WriteLine(args[1]);
	}//end Main
}//end class testClass

* Compiler Error
* Runtime Error
* Hello C# world
* None of the above

Answer :

Runtime Error


Question 31 :

What will be the output of the following code snippet?

using System;
class MainClass{
	static void Main( ){
		new MainClass().Display( 3.56 );
	}

	private void Display( float anArg ){
		Console.Write( "{0} {1}", anArg.GetType(), anArg );
	}

	double Display( double anArg ){
		Console.Write( "{0} {1}", anArg.GetType(), anArg );
		return anArg;
	}

	public decimal Display( decimal anArg ){
		Console.Write( "{0} {1}", anArg.GetType(), anArg ); return anArg;
	}
}

* System.Single 3.56
* System.Float 3.56
* System.Double 3.56
* System.Decimal 3.56

Answer :

System.Double 3.56


Question 32 :

What will be output for the given code?

Dim I as integer = 5
Do
I = I + 2
Response.Write (I & " ")
Loop Until I > 10

* 5 8
* 5 7 9
* 7 9 11
* Errors out 

Answer :

7 9 11 (if corrected)