Very Basic .Net Interview Questions Part 2

Q: What is difference between weakly name assembly and strongly named assembly?

Ans: Both weakly named and strongly name assemblies are identical in structure and functionality. Main difference between them is strongly named assembly is signed with publishers public/private key to uniquely identification of assembly, secured and versioned. Strongly name assembly can be deployed any where on machine even on internet.

Q: What are methods for assembly deployment?

Ans: Assembly can deployed in two way 1. Privately 2. Globally

Privately deployed assembly is an assembly that is deployed in the application’s base directory or one of its subdirectories. A weakly named assembly can be deployed only privately.

Globally deployed assembly is an assembly that is deployed into some well-known location that the CLR looks in when it’s searching for the assembly(Like GAC). A strongly named assembly can be deployed privately or globally.

Q: What is GAC?

Ans: GAC stands for global assembly cache.

If an assembly you want to access from many application then you must have to deploy you assembly in a shared location from where your all application can access it and CLR can easily search it. This well known location is called GAC and normally on windows this path is C:Windowsassembly.

In this location actual file is not saved but a structure is created in which all information of your shared assembly is stored like Name, Culture, Version, Public Key etc info is created.

To register(share) and unregister your assembly in GAC always use GACUtil.exe tool.

Q: What is an strongly named assembly?

Ans: A strongly named assembly has a file name, an assembly version, and a culture. In addition, a strongly named assembly is signed with the publisher’s private key.

Q: How a strongly named assembly will be identified as unique?

Ans: A strongly named assembly consists of four attributes that uniquely identify the assembly: a file name (without an extension), a version number, a culture identity, and a public key.

“MyTypes, Version=1.0.8123.0, Culture=neutral, PublicKeyToken = b77a5c5656884e089”

Q: What is public key token?

Ans: Since public keys are very large numbers, we frequently use a small hash value derived from a public key. This hash value is called a public key token.

Questions on Types

Q: From which class all dot net types are derived?

Ans: The dot net requires every type to be derived from the System.Object type.

    //Implicitly Inherits System.object
    class Person
    //Explicitly inherits System.object
    class Person : System.Object

Both are equivalent.

Q: What are methods of System.Object ?

Ans: Protected Methods

  1. MemberwiseClone()
  2. Finalize()

For more details of these methods please refer MSDN.

Public Methods

  1. Equals(), used to compare two objects.
  2. GetHashCode(), Computes has code for object .
  3. ToString(), By default returns name of type.
  4. GetType(), returns instance of a Type-derived object that identifies the type of the object used to call GetType.

Q: What is difference between ‘is’ and ‘as’ operators?

Ans: The is operator checks whether an object is compatible with a given type, and the result of the evaluation is a Boolean: true or false.

    Object o = new Object();
    bool b1 = (o is Object); // b1 is true.
    bool b2 = (o is Person); // b2 is false.

The as operator works just as casting does except that the as operator will never throw an exception. Instead, if the object can’t be cast, the result is null. You’ll want to check to see whether the resulting reference is null, or attempting to use the resulting reference will cause a System.NullReferenceException to be thrown.

    Object o = new Object(); // Creates a new Object object
    Person e = o as Person; // Casts o to an Employee
    // The cast above fails: no exception is thrown, but e is set to null.

Q: What is namespaces in dot net ?

Ans: Namespaces are used to doing logical grouping of types in assembly. It is just like folder file structure.

For example System.Object, in this type System is a namespace. You can use Object directly by using ‘using’ directive and compiler makes full name of type like ‘system.Object’ because  CLR not understand namespaces it understand full name of type with periods.

Leave a Reply

Your email address will not be published. Required fields are marked *