OOPS interview questions and answers in C#.Net-part4

91)What is dll hell problem?

    -in windows environment all application dll s are copied to system32 folder of windows directory,so that there is a chance of overwriting   one application dll by another application dll.
    -if share dll s are used by multiple applications then due to uninstallation of one application another application may be effected which is called as dll hell problem.

92)Explain different parts of assembly version?

     Assembly version contains four parts
      a)major:this part indicates the new namespace,class ,interface ,delegate insertion into assembly
      b)minor:this part indicates the new methods ,properties insertion into assembly
      c)Build:this part indicates number of times bugs fixed in assembly
      d)revision:this part indicates how many times assembly has been rebuilt irrespective of bugs reported or not

93)What is the purpose of checked and unchecked blocks?

     -checked block is used to provide a piece of code where there is a chance of raising OverFlowException.
     -Unchecked block does raise OverFlowException.

94)What is typeof()?

   -it is operator which is used to extract complete type information dynamically.
   -it will return System.Type object.

95)What is difference between function and event in C#?


Events are like triggers or actions that are associated with an object. For example for a button, Click is an event. For DropDownList, SelectedIndexChanged is an event. The code that runs against an event, is known as Event Handler


Methods  are a block of statements.Which is called by prgrammers either using by object or classname.

96) Extension method code example?


namespace Extentionmethod

{
Public static class Extention
{
public static int WordCount(this String str)
{
return str.Split(new char[] { ' ', '.', '?' },StringSplitOptions.RemoveEmptyEntries).Length;)
}
}
}

string s = "Hello Extension Methods";

int i = s.WordCount();

97)What is ASP.NET Dynamic Data?


ASP.NET Dynamic Data is a framework. using this you create data-driven ASP.NET Web applications easily.

It does this by automatically discovering data-model metadata at run time and deriving UI behavior from it.
Scaffolding is best example for this.

98)Can we use same method name , what we have in base class without overriding the method?


yes we can ues with help of new keyword.


public class BCl

{
    public void DoWork() { WorkField++; }
    public int WorkField;
    public int WorkProperty
    {
        get { return 0; }
    }
}

public class DerivedClass : BaseClass

{
    public new void DoWork() { WorkField++; }
    public new int WorkField;
    public new int WorkProperty
    {
        get { return 0; }
    }
}

99)Use of sealed keyword in  C#?

using sealed keyword stop the class from inheritance.

Another is we can stop inheritence of virtual methods to its derived classes

   class A
    {
        public virtual void dis() { }
        public virtual void display()
        {
            Console.WriteLine("I am from virtaul base class");
        }
       
    }
    class B : A
    {
        public override  sealed void display()
        {
            Console.WriteLine(" I am from derived");
        }
        
    }
    class D : B
    { 
         
    // Class D not getting the methods of B

    }

100)Can we declare class as private in C#?

yes ,only for nested class 

 class Program
    {
       static void Main(string[] args)
       {
       }
        private class Private_ClassExample
        { 
        
        }
    }

 101) What Do you mean Delegate Invoke/BeginInvoke in C# ?


Delegate.Invoke: Executes synchronously, on the same thread.

Delegate.BeginInvoke: Executes asynchronously, on a threadpool thread.

102)Can we create nullable types based on reference type?


No, we can not create nullable types to reference type, We create nullable types only for value types


103)Can we use dynamic type as method parameter ?


yes.


class Program

{
        public void Dispaly(dynamic a)
        {
            Console.WriteLine(a);
            Console.WriteLine("I am from dynamic");
        }
        static void Main(string[] args)
        {
            Program Pobj = new Program();
            Pobj.Dispaly("Rama");
            Console.ReadLine();
        }
}

104)Difference between where and any clauses linq in C# ?


Where returns a new sequence of items matching the predicate.


Any returns a Boolean value;


105)Can we do implicit conversation with Var keyword?


No 


-explicit conversation is possible.


-with Dynamic keyword its possible.


106)What is the difference between obj and bin folder in C#?


Obj :This folder contain a temporary files or intermediatory files which is generated by compiler during the copilation and it is useful when do next build if source does not have any change. 


bin :This folder contains result of the build its contain exe files , xml files etc


107)How to use Multicast Delegates in C#?


Using multicast delegates executing multiple methods at one time that methods may belongs to same class or diffrent classes.


In multicast delegates one delegate points to one function 


Added all the delegates using + operator and assign this another delegate


 namespace Multicast_Delegates

{
    public delegate void muldel();
    class GeneralInfo
    {
        public void DisplayFN()
        {
            Console.WriteLine("Gummadidala");
        }
        public void displayLN()
        {
            Console.WriteLine("Shiva");
        }

    }

    public class Addtional
    {
        public void Qualification()
        {
            Console.WriteLine("MCA");
        }
    }
    public class Program
    {
        static void Main(string[] args)
        {
            GeneralInfo pobj = new GeneralInfo();
            muldel ml, add, res, qul;
            ml = pobj.DisplayFN;
            add = pobj.displayLN;
            Addtional aobj = new Addtional();
            qul = aobj.Qualification;
            res = add + ml + qul;
            res.Invoke();

            Console.Read();

        }
    }
}


108)What is private Constructor in C#?

If class contains atleast one private constructor inheritence not possible to that constructor.


If a class has  private constructor and no public constructor, other classes cannot create instances of this class.


Private constructor is used in classes that contain static members only.


109)What is default access modifier for constructor in C# ?

 
If class is private , default access modifier of constructor is private.
Generally accessibility member is not greater than the type that contains it.

110)How to implementing few methods of a interface in C# ?


  public interface I1
    {
        void m1();
        void m2();
        void m3();
    }
   abstract class Program : I1
    {
        public void m1()
        {

        }

       public abstract void m2();
       public abstract void m3();

    }

111)What is the difference between constant , readonly , static readonly varibales in C#?

Constant:

Constant variables are represent with const keyword.

we need to assign the values before compilation.
 public class ConstantReadonly
    {
        public const int a = 5;
  
    }

Readonly:

Readonly variables change at runtime with in constructors not with static constructors, 

if you want , you can assign it at compile time but you cannot change.


 public class ConstantReadonly
    {

        public readonly int b;
      
        public ConstantReadonly()
        {
            b = 3;
        }
    }

Static readonly:

A Static Readonly type variable's values change at runtime with static constructors , not with instance constructors 

if you want , you can assign it at compile time but you cannot change.

 public class ConstantReadonly
    {
       
        public static readonly int b;
      
        static ConstantReadonly()
        {
            b = 3;
        }         
   }

112)Reverse of a number logic ?

            int i = 153;
            int n = 0,sum = 0;
            while (i > 0)
            {
                n = n * 10; 
                n = n+ i%10; 
                i = i / 10;
            }
           Console.WriteLine( n);

113)What is exact difference between equality Operator ( ==) and Equals() Method in C#?

== is working based on reference of a variables 
Equals() method is working based on content

114)What is declarative and imperative programming?

Declarative programming says write what you want , Lets framework achieve it 

List<int> lstNumbers = new List<int>{10,11,12,13,14};
var oddNumbers = lstNumbers.where(x=>x%2 !=0)

Imperative programming says write step by step procedure to achieve something you want

List<int> lstNumbers = new List<int>{10,11,12,13,14};
List<int> oddNumbers = new List<int>();
foreach(var num in lstNumbers)
{
if(num%2 != 0)
oddNumbers.Add(num);
}

115)How many types of serialization available in .Net?

Persistent state of an object to transport is known as serialization. There are three serializing techniques available
1) Binary Serialization
2)Xml and SOAP serialization
3)JSON serialization.

What is Binary Serialization in .NET?

For Part-3 click here

For Part-2   click here

Thanks for visiting this blog. How is the content?. Your comment is great gift to my work. Cheers.

No comments:

Post a Comment