Tuesday 22 March 2016

question & answer

What is a static class?
-A class that cannot be instantiated
-It is best for use with common code libraries

What is a singleton?
-A class that provides a single instance of itself

What is the difference between a static class and a singleton?
-A static class cannot be instantiated
-A singleton can instantiate itself and provide that instance



Object
Represents one specific thing Example: Hammer or Saw
Defines one thing created from that template
Created at runtime with the new keyword

Class
Represents things of the same type
Example: Product
Defines the template specifying the data and processing associated with all things of that type
Created at development time with code


What is the difference between a constant and a read-only field?
-A constant
•Is static
•Assigned on the declaration
•Assigned to an expression that is fully evaluated at compile time
-A read-only field
•Can be static or non-static
•Assigned in the declaration or in a constructor
•Assigned to any valid expression
What is the primary purpose of a property?
-To guard access to the fields of the class
-And optionally provide a location for logic

What are auto-implementedproperties?
-Short cut syntax for defining an implicit backing field with its associated property getter and setter


What is the primary purpose of a method?
-To implement the logic required for specific behavior or functionality in a class

What is the difference between a parameter and an argument?
-A parameteris part of the method signature
-An argumentis part of the method call

What is method overloading?
-Methods with the same name and purpose but different signatures

What is method chaining?
-One method overload calls another overload to prevent repeated code

When is it best to use method overloading vs. method overriding?
-Use overloading when one method requires multiple signatures
•Such as a GetCustomer(id) to get a customer by Id and GetCustomer(name)

to get the customer by name
-Use overridingwhen replacing a method defined higher up the object

hierarchy.
•Such as replacing the ToString() method

What is an expression-bodied method?
-A syntax shortcut for single statement methods that return a value

What does it mean to say that C# strings are immutable?
-It means that strings cannot be modified once they are created.
§Is a string a value type or a reference type?
-A string is a referencetype
-That acts like a valuetype
§What is the best way to check for nullstrings?
-
It depends
-
Using String.IsNullOrWhiteSpaceis great when checking nulls for a code block
-
Using the new C# 6 null-conditional operator is great for code statements
[18:35:30] Shantanu Patel | Extension 3363: What are the benefits to using StringBuilder?
-The .NET StringBuilderclass is mutable, meaning that it can be readily changed.
-Using StringBuilderis therefore more efficient when appending lots of strings.
[18:37:43] Shantanu Patel | Extension 3363: using System;

class Program
{
    static void Main()
    {
 int val = 0;

 Example1(val);
 Console.WriteLine(val); // Still 0!

 Example2(ref val);
 Console.WriteLine(val); // Now 2!

 Example3(out val);
 Console.WriteLine(val); // Now 3!
    }

    static void Example1(int value)
    {
 value = 1;
    }

    static void Example2(ref int value)
    {
 value = 2;
    }

    static void Example3(out int value)
    {
 value = 3;
    }
}

Output

0
2
3

No comments:

Post a Comment