*
Previous C# Question Answers-1 - 10 C# Question Answers-21 - 30 Next

C# (C-Sharp) Question Answers - 11-20

11. Can you store multiple data types in System.Array?

No

12. Conceptually, what is the difference between early-binding and late-binding?

Early binding means compiler gets information of type calling/path execution during compilation of code and in late binding compiler doesn’t get that information but this information determined at runtime/execution time.

The short answer is that early (or static) binding refers to compile time binding and late (or dynamic) binding refers to runtime binding (for example when you use reflection).

  • Compile Time Polymorphism (Called as Early Binding or Overloading or static binding)
  • Run Time Polymorphism (Called as Late Binding or Overriding or dynamic binding)

13. Define marshalling

  • The process of gathering data and transforming it into a standard format before it is transmitted over a network so that the data can transcend network boundaries. In order for an object to be moved around a network, it must be converted into a data stream that corresponds with the packet structure of the network transfer protocol. This conversion is known as data marshalling. Data pieces are collected in a message buffer before they are marshaled. When the data is transmitted, the receiving computer converts the marshaled data back into an object.
  • Data marshalling is required when passing the output parameters of a program written in one language as input to a program written in another language.

14. Describe the accessibility modifier “protected internal”.

It is available to classes that are within the same assembly and derived from the specified base class.

15. Describe the difference between a Thread and a Process?

Thread is the part of Process. One process may have many Threads.

Each process provides the resources needed to execute a program. A process has a virtual address space, executable code, open handles to system objects, a security context, a unique process identifier, environment variables, a priority class, minimum and maximum working set sizes, and at least one thread of execution. Each process is started with a single thread, often called the primary thread, but can create additional threads from any of its threads.

A thread is the entity within a process that can be scheduled for execution. Threads can also have their own security context, which can be used for impersonating clients.

16. Difference between IEnumerable and IQueryable?

  • IEnumerable: While querying data from database, it executes select query on server side, loads data in-memory on client side and then filters data. Hence does more work and becomes slow.
  • IQueryable: While querying data from database, it executes select query on server side with all filters. Hence does less work and becomes fast.

17. Difference between Parse and TryParse?

Both are used to convert string to int, date etc.

The TryParse method is like the Parse method, except the TryParse method does not throw an exception if the conversion fails. It eliminates the need to use exception handling to test for a FormatException in the event that string is invalid and cannot be successfully parsed.

18. Difference between static class and singleton pattern?

  • The big difference between a singleton and a bunch of static methods is that singletons can implement interfaces (or derive from useful base classes, although that's less common), so you can pass around the singleton as if it were "just another" implementation.
  • A singleton class allows creation of only a single instance of a particular class. That instance can be treated as a normal object. You can pass that object to a method as parameter or you can call the class method with that singleton object. While static class can have only static methods and you cannot pass static class as parameter.
  • We can implement interfaces with the Singleton class while we cannot implement interfaces with static classes.
  • We can clone the object of Singleton classes; we cannot clone the object of static classes.
  • Singleton objects are stored on heap while static class is stored in stack.
  • A Singleton class can extend classes (supports inheritance) while static class cannot inherit classes.
  • Singleton class can initialize lazily while static class initializes when it is first loaded.
  • Static classes are sealed classes while Singleton classes are not sealed.

19. Explain Task, Task<TResult> and Task.ContinueWith

  • Task: Represents an asynchronous operation.
  • Task<TResult>: An asynchronous operation that returns a value.
  • Task.ContinueWith: A continuation that is started after the operation in the Task is completed.

20. Explain "Method Syntax (Method Invocation)" in LINQ?

Method syntax is complex as compared to Query expression since it uses lambda expression to write LINQ query. It is easily understood by .NET CLR. Hence at compile time, Query expression is converted into Method Invocation. The result of a Method syntax is also a query object, which is usually a collection of type IEnumerable<T> or IQueryable<T>.

// Data
List<int> numbers = new List<int>() { 11, 22, 33, 44, 55, 66, 77, 88, 99, 100 }; 
// Method based syntax 
IEnumerable<int> query = numbers.Where(num => num > 55 && num < 100); 

// result: 66,77,88,99
Back to Index
Previous C# Question Answers-1 - 10 C# Question Answers-21 - 30 Next
*
*