Floating FB popout byF5debug

Interview Questions and Answers on .Net Framework, OOPS, ASP.Net, C#.Net, SQL Server, WCF Series – Part 14


Question 131 – What is Shadowing or Hiding?

  • When global and local variable are in the same name, the local variable in a method which use to override the global is called the shadowing. ie the Global variable is being shadowed by local variable.
  • When two elements in a program have the same name, one of them can hide and shadow the other one. So in such cases the element which shadowed the main element is referenced.
  • This is a VB.Net Concept by which you can provide a new implementation for the base class member without overriding the member.
    Hiding is the C# concept equivalent for shadowing.
  • You can shadow a base class member in the derived class by using the keyword Shadows.
  • Shadowing is bad programming practice according to OOPs concepts.
  • In shadowing signature could be different.
  • In Shadowing both Derived class and Base Class methods are available for use.(So it’s a bad practice)
  • The access level signature and the return type can only be changed when you are shadowing with VB.NET. Hiding and overriding demands the these parameters as same in C#.


Question 132 – What are Out and Ref parameters?

  • The out parameter -  return the values in the same variable passed as a parameter of the method. Any changes made to the parameter will be reflected in the variable.
  • The ref keyword on a method parameter causes a method to refer to the same variable that was passed as an input parameter for the same method. If you do any changes to the variable, they will be reflected in the variable.
  • The implementation of ref and out parameter in IL Code(in CLR) is same, there is no difference whether you use ref or out parameters.


Question 133 – What are the differences of Out and Ref Parameters?

REF
OUT
Ref must be initialized before it is passed to the method Out its is not necessary, but after method call it should get initialized
Extra performance cost. Faster
The called method can read the argument at any time The called method must initialize the parameter before reading it
ref parameters are used to get a value and return a change to that value(Secondary value) out parameters are used when you just need to get a secondary return value

 

Question 134 – What are the differences between String and String Builder?

String
String Builder
String objects are immutable, which means that once they are created they cannot be changed. When we use one of the methods of the String class, we create a new string object. StringBuilder are mutable class, which means when concatenate any text to the variable it allows us to modify the original value without creating a new object.
Here concatenation is used to combine two strings. Here Append method is used.
String object is used to concatenate two strings. Stringbuilder object is used.
The first string is combined to the other string by creating a new copy in the memory as a string object, and then the old string is deleted Insertion is done on the existing string.
Less efficient StringBuilder is more efficient for large amounts of string manipulations

 

Question 135 – Why C# is strongly typed language?

C# is called Strongly Typed Language because its type rules are very strict. For example you can't called a function that is designed to call Integer with a string or decimal. If you want to do so then you will have to explicitly convert them to integer.

 Question 136 – What are Imperative and Interrogative function?

  • Imperative methods return values or provide information back to the calling code. It returns a value.
  • Interrogative methods, just perform a service and return nothing to the calling code. It does not return a value.


Question 137 – What is a Collection Class?

  • A collection is a set of the same type of objects that are grouped together and that is able to supply a reference to an enumerator. Part of the System.Collections or System.Collections.Generic namespace
  • An enumerator is an object that iterates through its associated collection. It can be thought of as a movable pointer pointing to any element in the collection. In order to provide an enumerator, a class must implement the IEnumerable interface.
  • Most collection classes derive from the interfaces ICollection, IComparer, IEnumerable, IList, IDictionary, and DictionaryEnumerator and their generic equivalents.
  • Using generic collection classes provides increased type-safety and in some cases can provide better performance, especially when storing value types.


Question 138 – What are the differences between Const & Readonly?

Const
Read Only
Must be initialized at the time of its creation Assigned in constructor and called at Runtime
Used if we want to define something at compile time. At Runtime you can make use of the value
Protects from accidentally changing value of the field
 
Can't be static. Can be either instance-level or static.
Value is evaluated at compile time. Value is evaluated at run time.
Initialized at declaration only. Initialized in declaration or by code in the constructor



Question 139 – What is a Stack?

  • Stack is responsible of keeping track of running memory needed in your application.
  • As the name says stack it stacks this memory allocation on the top of the first memory allocation. You can think about stack as series of compartment or boxes put on top of each other.
  • Memory allocation and de-allocation is done using LIFO (Last in first out) logic. In other words memory is allocated and de-allocated at only one end of the memory i.e. top of the stack.
  • Reference pointers are allocated on stack.
  • At the end event clears all the memory variables which are assigned on stack
  • Static Memory – Stack
  • Details stored in stack are Name, Data type and Value of the variable.


Question 140 – What is a Heap?

    • It creates a pointer on the stack and the actual object is stored in a different type of memory location called as ‘Heap’. ‘
    • Heap’ does not track running memory it’s just pile of objects which can reached at any moment of time.
    • Heap is used for dynamic memory allocation. FIFO (‘First In First Out’)
    • Instance created using new keyword it will be in HEAP.
    • It did not de-allocate the heap memory. This memory will be later de-allocated by “Garbage Collector”.
    • Dynamic Memory – Heap


Disclaimer – F5debug Interview Questions & Answers Series:

You may recopy extracts from these pages ("the material") to individual third party websites or to any intranet websites, but only if:
You acknowledge www.f5debug.net as the source of the material. Such acknowledgment should include reference to www.f5debug.net in the copy of the material and should also include “© Karthikeyan Anbarasan, www.f5debug.net ". You inform the third party that these conditions apply to him/her and that he/she must comply with them.

About Author: Karthikeyan Anbarasan, Microsoft MVP (Most Valuable Professional) in ASP.NET/IIS Architecture. He is the Founder and Chief Editor of the www.f5debug.net website and has authored books on Windows Phone and Business Intelligence(SSIS). He is also a Passionate Speaker and a Blogger on Microsoft Technologies.

You can Join Me On: Facebook, Twitter, Google Plus, LinkedIn

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Recent Posts

Random Posts

Most Viewed

URL Shortner

Create your own short urls!!!

Site Counter

free counters

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer. For accuracy and official reference refer to MSDN/ TechNet. I have documented my personal experience on this blog.

Protected by Copyscape Web Plagiarism Finder

Site Meter