1. Question:what is optional parameters and named arguments? 

    Answer
    Parameters are optional when a default value is specified as part of a declaration.
    Example: public List<Product> GetProductByCategory(string category, int pageIndex=0){}
    Here pageIndex is an optional parameter.
    Named arguments allow us to explicitly name an argument we are passing to a method – instead of just identifying it by argument position. 
    Example: var products= GetProductByCategory(“beverages”, pageIndex=2){} here pageIndex is a named argument.

    1. Report
  2. Question:What is Upcasting and Downcasting. 

    Answer
    Upcasting: An upcast operation creates a base class reference from a subclass reference.
    Example:
    Stock msft = new Stock();
           Asset a = msft;
    Downcasting: A downcast operation creates a subclass reference from a base class reference. Example:
    Stock msft = new Stock();
           Asset a = msft;
           Stock s = (Stock)a;

    1. Report
  3. Question:Define Sealing function and classes. 

    Answer
    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.

    1. Report
  4. Question:Define dynamic, static, custom and language binding? 

    Answer
    Dynamic binding :Dynamic  binding defers  binding—the  process  of  resolving  types,  members,  and
    operations—from  compile  time  to  run-time.Static binding : It is defined as, when we compile our program and an object type is determined then it is known as static binding or early binding.Custom binding : Defines a binding from a list of binding elements.Language binding : Language  binding  occurs  when  a  dynamic  object  does  not  implement
    IDynamicMetaObjectProvider

    1. Report
  5. Question:Define Boxing and Unboxing. 

    Answer
    Boxing:Boxing is the process of converting a value type to the object type or to any interface type implemented by this value type. When the CLR boxes a value type, it wraps the value inside a System.Object and stores it on the managed heap. Unboxing: Unboxing extracts the value type from the object. Boxing is implicit; unboxing is explicit. The concept of boxing and unboxing underlies the C# unified view of the type system in which a value of any type can be treated as an object.

    1. Report
  6. Question:Write difference between classes and structs in C#. 

    Answer
    1. Classes are Reference types and Structures are Values types. 
    2. Classes can have explicitly parameterless constructors whereas structures can’t.
    3. A variable can be null if it’s a class, but is never null if it’s a struct.
    4. Member variable initialization is possible in class whereas in Structures, it is not.

    1. Report
  7. Question:What is Lamda expressions. 

    Answer
    A lambda expression is an unnamed method written in place of a delegate instance.
    The compiler immediately converts the lambda expression to either:
    • A delegate instance.
    • An expression tree, of type  Expression<TDelegate>

    1. Report
  8. Question:What is overloading constructor? 

    Answer
    Constructor overloading in C# is a type of Static Polymorphism. Using constructor overloading, any number of constructors can be defined for the same class. But ensure each constructor must have different number and type of parameters defined.

    1. Report
  9. Question:Static vs Non static members? 

    Answer
    Static Member :The static member is callable on a class even when no instance of the class has been created. The static member is always accessed by the class name, not the instance nameNon-static Member :

    1. Report
  10. Question:Briefly describe C# access modifiers. 

    Answer
    Access modifiers are keywords used to specify the declared accessibility of a member or a type. Access modifiers are an integral part of object-oriented programming.  There are 5 different types of Access Modifiers: 
    1. Public.
    2. Internal.
    3. Private.
    4. Protected.
    5. Protected internal.

    1. Report
Copyright © 2024. Powered by Intellect Software Ltd