Dot Net Technology Que/Ans Set-6

| Tuesday 7 June 2011

52. How do you generate a strong name?
.NET provides an utility called strong name tool. You can run this toolfrom the VS.NET command prompt to generate a strong name with an option "-k" and providing the strong key file name. i.e. sn- -k < file-name >
What is the difference between a Debug and Release build? Is there a significant speed difference? Why or why not?
The Debug build is the program compiled with full symbolic debug information and no optimization. The Release build is the program compiled employing  optimization and contains no symbolic debug information. These settings can be changed as per need from Project Configuration properties. The release runs faster since it does not have any debug symbols and is optimized.
53. Explain the use of virtual, sealed, override, and abstract. Abstract: The keyword can be applied for a class or method.
1. Class: If we use abstract keyword for a class it makes the
class an abstract class, which means it cant be instantiated. Though
it is not nessacary to make all the method within the  abstract class to be virtual. ie, Abstract class can have concrete methods
2. Method: If we make a method as abstract, we dont need to provide implementation of the method in the class but the derived class need to implement/override this method.
Sealed: It can be applied on a class and methods. It stops the type from further derivation i.e no one can derive class
from a sealed class,ie A sealed class cannot be inherited.A sealed class cannot be a abstract class.A compile time error is thrown if you try to specify sealed class as a  base class.
When an instance method declaration includes a sealed modifier, that method is said to be a sealed method. If an instance method declaration includes the sealed modifier, it must also include the override modifier. Use of the sealed modifier prevents a derived class from further overriding the method  For Egs: sealed override public void Sample() { Console.WriteLine("Sealed Method"); }

Virtual & Override: Virtual & Override keywords provides runtime polymorphism. A base class can make some of its methods
as virtual which allows the derived class a chance to override the base class implementation by using override keyword.

For e.g. class Shape
  {
  int a
  public virtual void Display()
  {
   Console.WriteLine("Shape");
  }
 }

 class Rectangle:Shape
 {
  public override void Display()
  {
   Console.WriteLine("Derived");
  }
 }

54. Explain the importance and use of each, Version, Culture and PublicKeyToken for an assembly. Ans:This three alongwith name of the assembly provide a strong name or fully qualified name to the assembly. When a assebly is referenced with all three.
PublicKeyToken: Each assembly can have a public key embedded in its manifest that identifies the developer. This ensures that once the assembly ships, no one can modify the code or other resources contained in the assembly.
Culture: Specifies which culture the assembly supports

Version: The version number of the assembly.It is of the following form major.minor.build.revision.
Explain the differences between public, protected, private and internal.
These all are access modifier and they governs the access level. They can be applied to class, methods, fields.
Public: Allows class, methods, fields to be accessible from anywhere i.e. within and outside an assembly.
Private: When applied to field and method allows to be accessible within a class.
Protected: Similar to private but can be accessed by members of derived class also.
Internal: They are public within the assembly i.e. they can be accessed by anyone within an assembly but outside assembly they are not visible.
55. What is the difference between typeof(foo) and myFoo.GetType()? Typeof is operator which applied to a object returns System.Type object. Typeof cannot be overloaded white GetType has lot of overloads.GetType is a method which also returns System.Type of an object. GetType is used to get the runtime type of the object.
Example from MSDN showing Gettype used to retrive type at untime:-
public class MyBaseClass: Object {
}
public class MyDerivedClass: MyBaseClass {
}
public class Test {
   public static void Main() {
      MyBaseClass myBase = new MyBaseClass();
      MyDerivedClass myDerived = new MyDerivedClass();
      object o = myDerived;
      MyBaseClass b = myDerived;
      Console.WriteLine("mybase: Type is {0}", myBase.GetType());
      Console.WriteLine("myDerived: Type is {0}", myDerived.GetType());
      Console.WriteLine("object o = myDerived: Type is {0}", o.GetType());
      Console.WriteLine("MyBaseClass b = myDerived: Type is {0}", b.GetType());
   }
}

/*
This code produces the following output.
mybase: Type is MyBaseClass
myDerived: Type is MyDerivedClass
object o = myDerived: Type is MyDerivedClass
MyBaseClass b = myDerived: Type is MyDerivedClass
*/
56. Can "this" be used within a static method? No 'This' cannot be used in a static method. As only static variables/methods can be used in a static method.
57. What is the purpose of XML Namespaces?
Ans: An XML Namespace is a collection of element types and attribute names. It consists of 2 parts
1) The first part is the URI used to identify the namespace
2) The second part is the element type or attribute name itself.
Together they form a unique name. The various purpose of XML Namespace are
1. Combine fragments from different documents without any naming conflicts. (See example below.)
2. Write reusable code modules that can be invoked for specific elements and attributes. Universally unique names guarantee that
such modules are invoked only for the correct elements and attributes.
3. Define elements and attributes that can be reused in other schemas or instance documents without fear of name collisions. For
example, you might use XHTML elements in a parts catalog to provide part descriptions. Or you might use the nil attribute
defined in XML Schemas to indicate a missing value.
< Department >
     < Name >DVS1< /Name >
     < addr:Address xmlns:addr="
http://www.tu-darmstadt.de/ito/addresses" >
        < addr:Street >Wilhelminenstr. 7< /addr:Street >
        < addr:City >Darmstadt< /addr:City >
        < addr:State >Hessen< /addr:State >
        < addr:Country >Germany< /addr:Country >
        < addr:PostalCode >D-64285< /addr:PostalCode >
     < /addr:Address >
     < serv:Server xmlns:serv="
http://www.tu-darmstadt.de/ito/servers" >
        < serv:Name >OurWebServer< /serv:Name >
        < serv:Address >123.45.67.8< /serv:Address >
     < /serv:Server >
  < /Department >
58. What is difference between MetaData and Manifest ? Metadata and Manifest forms an integral part of an assembly( dll / exe ) in .net framework . Out of which Metadata is a mandatory component , which as the name suggests gives the details about various components of IL code viz : Methods , properties , fields , class etc.
Essentially Metadata maintains details in form of tables like Methods Metadata tables , Properties Metadata tables , which maintains the list of given type and other details like access specifier , return type etc.
Now Manifest is a part of metadata only , fully called as “manifest metadata tables” , it contains the details of the references needed by the assembly of any other external assembly / type , it could be a custom assembly or standard System namespace .
Now for an assembly that can independently exists and used in the .Net world both the things ( Metadata with Manifest ) are mandatory , so that it can be fully described assembly and can be ported anywhere without any system dependency . Essentially .Net framework can read all assembly related information from assembly itself at runtime .
But for .Net modules , that can’t be used independently , until they are being packaged as a part of an assembly , they don’t contain Manifest but their complete structure is defined by their respective metadata .
Ultimately . .Net modules use Manifest Metadata tables of parent assembly which contain them .

59. What is the use of Internal keyword?
Ans: Internal keyword is one of the access specifier available in .Net framework , that makes a type visible in a  given assembly , for e.g : a single dll can contain multiple modules , essentially a multi file assembly , but it forms a single binary component , so any type with internal keyword will be visible throughout the assembly and can be used in any of the modules .

60. What actually happes when you add a something to arraylistcollection ? Following things will happen :
Arraylist is a dynamic array class in c# in System.Collections namespace derived from interfaces – ICollection , IList , ICloneable , IConvertible  . It terms of in memory structure following is the implementation .
a. Check up the total space if there’s any free space on the declared list .
b. If yes add the new item and increase count by 1 .
c. If No Copy the whole thing to a temporary Array of Last Max. Size .
d. Create new Array with size ( Last Array Size + Increase Value )
e. Copy back values from temp and reference this new array as original array .
f. Must doing Method updates too , need to check it up .

0 comments:

Post a Comment

Popular Posts

Company Placement Papers

 

Copyright © 2010 All Question Papers Blogger Template by Dzignine