Tuesday, February 27, 2018

HCL

1.What is Singleton?
2.Difference between Singleton and Static
3.How Sring.Format work?
4. Can we call WebAPI controller from MVC controller?
Ans: using HttpClient we can.
5. If we have a constant in one library and we have changed its value than should we rebuild the project which has included this library.
Ans Yes, In case of constant you need to rebuild the both project while in case of readonly, static and instance variable no need to rebuild the project.

Consider a class defined in AssemblyA.

public class Const_V_Readonly
{
  public const int I_CONST_VALUE = 2;
  public readonly int I_RO_VALUE;
  public Const_V_Readonly()
  {
     I_RO_VALUE = 3;
  }
}

in the case of the const value, it is like a find-replace, the value 2 is 'baked into' the AssemblyB's IL. This means that if tomorrow I'll update I_CONST_VALUE to 20 in the future. AssemblyB would still have 2 till I recompile it.

in the case of the readonly value, it is like a ref to a memory location. The value is not baked into AssemblyB's IL. This means that if the memory location is updated, AssemblyB gets the new value without recompilation. So if I_RO_VALUE is updated to 30, you only need to build  AssemblyA. All clients do not need to be recompiled.

Source : https://stackoverflow.com/questions/55984/what-is-the-difference-between-const-and-readonly/56024#56024

6. How String.Format design for multiple arguments.
Ans using params object[]

7. Security in Web API.

No comments:

Followers

Link