Search

Monday, October 18, 2010

.Net Question

What is Polymorphism?
Polymorphism means same operation may behave differently on different classes.
Example of Compile Time Polymorphism: Method Overloading
Example of Run Time Polymorphism: Method Overriding

Example of Compile Time Polymorphism

Method Overloading
- Method with same name but with different arguments is called method overloading.
- Method Overloading forms compile-time polymorphism.
- Example of Method Overloading:
class A1
{
void hello()
{ Console.WriteLine(“Hello”); }

void hello(string s)
{ Console.WriteLine(“Hello {0}”,s); }
}


Example of Run Time Polymorphism

Method Overriding
- Method overriding occurs when child class declares a method that has the same type arguments as a method declared by one of its superclass.
- Method overriding forms Run-time polymorphism.
- Note: By default functions are not virtual in C# and so you need to write “virtual” explicitly. While by default in Java each function are virtual.
- Example of Method Overriding:
Class parent
{
virtual void hello()
{ Console.WriteLine(“Hello from Parent”); }
}

Class child : parent
{
override void hello()
{ Console
.WriteLine(“Hello from Child”); }
}

static void main()
{
parent objParent = new child();
objParent.hello();
}
//Output
Hello from Child.
*******************************************

What is the CLR?What is Microsoft's Common Language Runtime (CLR)? It is the life line of .NET applications. Before I describe the CLR - let's explain what is meant by runtime. A runtime is an environment in which programs are executed. The CLR is therefore an environment in which we can run our .NET applications that have been compiled to IL. Java programmers are familiar with the JRE (Java Runtime Environment). Consider the CLR as an equivalent to the JRE.





The above diagram shows various components of the CLR. Let's discuss each in details. has an in-depth analysis.
The Common Type System (CTS) is responsible for interpreting the data types into the common format - e.g. how many bytes is an integer.
The second component, the IL Compiler takes in the IL code and converts it to the host machine language. The execution support is similar to the language runtime (e.g. in VB the runtime was VBRunxxx.dll; however with VB.NET we do not need individual language runtimes anymore).
Security component in the CLR ensures that the assembly (the program being executed) has permissions to execute certain functions. The garbage collector is similar to the garbage collector found in Java. Its function is to reclaim the memory when the object is no longer in use, this avoids memory leaks and dangling pointers. The class loader component is similar to the class loader found in Java. Its sole purpose is to load the classes needed by the executing application.
Here's the complete picture.
The programmer must first write the source code and then compile it. Windows programmers have always compiled their programs directly into machine code - but with .NET things have changed. The language compiler would compile the program into an intermediate language "MSIL" or simply "IL" (much like Java Byte code). The IL is fed to the CLR then CLR would use the IL compiler to convert the IL to the host machine code.
.NET introduces the concept of "managed code" and "unmanaged code". The CLR assumes the responsibility of allocating and de-allocating the memory. Any code that tries to bypass the CLR and attempts to handle these functions itself is considered "unsafe"; and the compiler would not compile the code. If the user insists on bypassing the CLR memory management functionality then he must specifically write such code in using the "unsafe" and "fixed" key words (see C# programmers guide for details). Such a code is called "unmanaged" code, as opposed to "managed code" that relies on CLR to do the memory allocation and de-allocation.
The IL code thus produced has two major issues with it. First it does not take advantage of platform specific aspects that could enhance the program execution. (for example if a platform has some complicated graphics rendering algorithm implemented in hardware then a game would run much faster if it exploit this feature; however, since IL cannot be platform specific it can not take advantage of such opportunities). Second issue is that IL can not be run directly on a machine since it is an intermediate code and not machine code. To address these issues the CLR uses an IL compiler. The CLR uses JIT compilers to compile the IL code into native code. In Java the byte code is interpreted by a Virtual Machine (JVM). This interpretation caused Java applications to run extremely slow. The introduction of JIT in JVM improved the execution speed. In the CLR Microsoft has eliminated the virtual machine step. The IL code is compiled to native machine and is not interpreted at all. For such a compilation the CLR uses the following two JIT compilers:
Econo-JIT : This compiler has a very fast compilation time; but it produces un-optimized code - thus the program may start quickly but would run slow. This compiler is suitable for running scripts.
Standard-JIT: This compiler has a slow compilation time; but it produces highly optimized code. Most of the times the CLR would use this compiler to run your IL code.
Install Time Compilation: This technique allows CLR to compile your application into native code at the time of installation. So the installation may take a few minutes more - but the code would run at speeds close to a native C/C++ application.
Once your program has been compiled into host machine code, it can begin execution. During execution the CLR provides security and memory management services to your code (unless you have specifically used unmanaged code).

*************************************************************************************
What is Inheritance?

Inheritance, together with encapsulation and polymorphism, is one of the three primary characteristics (concept) of object-oriented programming Inheritance enables you to create new classes that reuse, extend, and modify the behavior that is defined in other classes The Class whose methods and variables are defined is called super class or base class The Class that inherits methods and variables are defined is called sub class or derived class Sometimes base class known as generalized class and derived class known as specialized class Keyword to declare inheritance is ":" (colon) in visual C#.
Benefits of using Inheritance

Once a behavior (method) or property is defined in a super class(base class),that behavior or property is automatically inherited by all subclasses (derived class). Code reusability increased through inheritance Inheritance provide a clear model structure which is easy to understand without much complexity Using inheritance, classes become grouped together in a hierarchical tree structure Code are easy to manage and divided into parent and child classes
Example of Inheritance

Types of Inheritance in C#: -

* Implementation Inheritance
* Multiple Inheritances (Interface Inheritance)

Implementation Inheritance

One base class (super class) and one derived class (sub class).
Example:

Interface Inheritance

An interface looks like a class, but has no implementation. It contains definitions of events, indexers, methods and properties. An interface inherited by classes An interface inheritance defined with keyword "interface". In C# Interface Inheritance also known as multiple inheritances.
Inheritance Tree Structure:


*******************************



Session Management

can be achieved in two ways

1)InProc

2)OutProcOutProc is again two types

1)State Server

2)SQL ServerInProcAdv.:

1) Faster as session resides in the same process as the application

2) No need to serialize the data
DisAdv.:

1) Will degrade the performance of the application if large chunk of data is stored

2) On restart of IIS all the Session info will be lost
State ServerAdv.:

1) Faster then SQL Server session management

2) Safer then InProc. As IIS restart won't effect the session data
DisAdv.:

1) Data need to be serialized

2) On restart of ASP.NET State Service session info will be lost

3)Slower as compared to InProc
SQL ServerAdv.:

1) Reliable and Durable

2) IIS and ASP.NET State Service restart won't effect the session data

3) Good place for storing large chunk of data
DisAdv.:

1) Data need to be serialized

2) Slower as compare to InProc and State Server

3)Need to purchase Licensed version of SQL Server


 
What is MVVM?
Model-View-ViewModel (aka Presentation Model), provides architectural solution for the Aplication with UI with complex interdependent interactions. Separate the UI(View) from the UI logic using a ViewModel that encapsulates the interactions and provides properties for a View to retrieve its state (and the state of its elements).
 
 What is Lambda Expression?
A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types.
 
What is difference betweeb VAR and Dynamic keybword in c#?
var dynamic
Introduced in C# 3.0 Introduced in C# 4.0
Statically typed – This means the type of variable declared is decided by the compiler at compile time. Dynamically typed - This means the type of variable declared is decided by the compiler at runtime time.
Need to initialize at the time of declaration.
e.g. var str=”I am a string”;
Looking at the value assigned to the variable str , the compiler will treat the variable str as string
No need to initialize at the time of declaration.
e.g. dynamic str;
str=”I am a string”; //Works fine and compiles
str=2;//Works fine and compiles
Errors are caught at compile time.
Since the compiler knows about the type and the methods and properties of the type at the compile time itself
Errors are caught at runtime
Since the compiler comes to about the type and the methods and properties of the type at the run time.
Visual Studio shows intellisense since the type of variable assigned is known to compiler. Intellisense is not available since the type and its related methods and properties can be known at run time only
e.g. var obj1; //will  throw a compile error since the variable is not initialized. The compiler needs that this variable should be initialized so that it can infer a type from the value. e.g. dynamic obj1; //will compile;
e.g. var obj1=1; //will compile
var obj1=” I am a string”;//will throw error since the compiler has already decided that the type of obj1 is System.Int32 when the value 1 was assigned to it. Now assigning a string value to it violates the type safety.
e.g. dynamic obj1=1; //will compile and run
dynamic obj1=” I am a string”;//will compile and run since the compiler creates the type for obj1 as System.Int32 and then recreates the type as string when the value “I am a string” was assigned to it.
This code will work fine.
 
 Why MVVM?
1. Separates UI from Model. If model needs to change, it can without changing the view and vice versa.
2. Avoids duplicated code to update views.
 3. Unit testable UI logic.
 4. You can use a 'viewmodel' to aggregate parts of your model that exist in separate classes/libraries to facilitate a more fluent interface for the 'view' to deal with.
5. Data-binding support with INotifyPropertyChanged, ICommand and IvalueConverters 6. Easy to refactor 7. Extensibility.
 
What are dependency properties?
These are dependency properties that belong to one class but can be used in another.
 Consider the below code snippet:-
<Rectangle Height="72" Width="131" Canvas.Left="74" Canvas.Top="77" /> 

4 7 9 
Height and Width are regular properties of the Rectangle. But Canvas.Top and Canvas.
 Left is dependency property as it belongs the canvas class. It’s used by the Rectangle to 
specify its position within Canvas.
 
What is a Routed event?
In a typical WPF application, it contains many elements. These elements exist in an element tree relationship with each other. A routed event is a type of event that can invoke handlers on multiple listeners in an element tree, rather than just on the object that raised the event.
 
What is 'One-way-to-Source ' binding property?
In One-way-to-Source binding when the target property changes, the source object gets updated.

What are XBAP'S?
They are basically WPF applications which run with .xbap extension in the browser.Their main features are:
1)They provide a page based navigation model .Root tag is Page. In page based navigation, we can navigate from one .Xaml file to another by using the standard techniques like HyperLinks, NavigationService, and we are provided with back and forward buttons in the toolbar that appears in the output to visit the pages that have been opened using HyperlInk, NavigationService.
2)They have restrictive permissions: example: we cannot do database connectivity, file handling or alter registries using XBAP's
3)We can do animations, drawings, transforms apply brushes on XBPAP files.
What is the difference between User Settings and Application Settings in WPF?
The User Settings are Read/Write, they can be read or write even at runtime and can be saved.
The Application Settings are read-only, they can only be written at design time.

How many type of templates are available in WPF..?
1) Data Templates: Data Template visual representation of data in control with style. like List box.
2) Control Templates: Control Template suppliers a visual representation of a UI Control like Button or List View.
3) Items Panel Templates: Item Panel Templates uses when we want to show data in Hierarchical way like child object use under parent object.

What are the different Data Binding Modes in Windows Presentation Foundation?
The different Data Binding Modes are:
1) OneWay: The target is updated when the source changes.
2) TwoWay: The target is updated when the source changes, and similarly, the source is updated when the target changes.
3) OneWayToSource: Only the source is updated when the target changes.
4) OneTime: The target is updated only the first time the source changes.
 
What is the importance of INotifyPropertyChanged in WPF?
* This interface contains a single event called "PropertyChanged" of the delegate type "PropertyChangedEventHandler".
* To notify the WPF/Silverlight framework whenever the value of a property changes in an object, fire the event in the "set" accessor of the property.
 
What is the importance of INotifyCollectionChanged in WPF?
* This interface is similar to INotifyPropertyChanged, which is to be implemented to notify the WPF/Silverlight framework whenever any changes occur in a collection, like adding an object or deleting an object.
* "ObservableCollection" is a built-in class which implements the INotifyCollectionChanged interface.
 
What is Logical Tree in WPF?
* Logical tree describes the relations between elements of the user interface.
* Every aspect of WPF (properties, events, resources, and so on) has behavior tied to the logical tree.
* Logical tree is responsible for:
1) Inherit Dependency Property values
2) Resolving Dynamic Resources references
3) Looking up element names for bindings
4) Forwarding Routed Events
* System.Windows.LogicalTreeHelper class is used to traverse the logical tree.

What is Visual Tree in WPF?
* Visual tree is an expansion of a logical tree, in which nodes are broken down into their visual components.
* Visual tree contails all logical elements including all visual elements.
* The elements that appear in a visual tree derive from 'System.Windows.Media.Visual' and 'System.Windows.Media.Visual3D'.
* Visual tree is responsible for:
1) Rendering visual elements
2) Propagate element opacity
3) Propagate layout and render transforms
4) Propagate the 'IsEnabled' property
5) Do hit-testing
NOTE:
* Visual tree is dependent on Windows theme.
* Visual tree is empty until the window undergoes layout at least once. So it must be navigated in 'OnContentRendered' event handler.
* System.Windows.VisualTreeHelper class is used to traverse the logical tree.

What is Dependency Properties and its Use in WPF?
* Dependency properties are used to enable styling, automatic data binding, templates, animation etc.
* All types that want to use DependencyProperties must derive from 'DependencyObject' class.
* The value of a DependencyProperty is resolved dynamically when read.
* The value of a dependency property is stored in a dictionary of keys and values provided by 'DependencyObject' class.
* Advantages:
1) Reduced memory footprint
2) Value Inheritance
3) Change Notification
What are the Types of Resources in WPF?
1) Binary Resources Binary resources could be logo/image files, AV files etc.
2) Logical Resources are of two types: Static and Dynamic Resources
* StaticResource finds the key defined within the ResourceDictionary under its scope during the Loading of the application. * Hence the Compiler will throw error during compilation if not found in resources. --
 * DynamicResource Markup Extension defers the resource assignment to the actual runtime of the application. * So the expression remains unevaluated until the object being created.
 
What are Binary Resources in WPF?
* Binary resources could be logo/image files, AV files etc.
* Resource files which are added to project, can have the “Build Action” defined on it from the file properties windows: -
Resource : Embeds resource into the assembly (or culture specific satellite assembly) -
Content : this leaves resource as loose file and upon compilation this resource information is not embedded to assembly. Instead, it adds custom attribute to the assembly (AssemblyAssociatedContentFile) which records the existence and relative location of file.
 
What are Static Resources in WPF?
* StaticResource finds the key defined within the ResourceDictionary under its scope during the Loading of the application.
* Hence the Compiler will throw error during compilation if not found in resources.
 
What are Dynamic Resources in WPF?
* DynamicResource Markup Extension defers the resource assignment to the actual runtime of the application.
 * So the expression remains unevaluated until the object being created.
 
What are Triggers and its type in WPF?
* The WPF styling and templating model enables you to specify Triggers within your Style.
 * Essentially, Triggers are objects that enable you to apply changes when certain conditions (such as when a certain property value becomes true, or when an event occurs) are satisfied.
* Types of triggers:
 1) Property triggers get active when a property gets a specified value.
2) Data triggers get active when a specified event is fired.
3) Event triggers get active when a binding expression reaches a specified value.
 
What are Templates and its type in WPF?
* A Template is used to change how a control looks.
 * Types of templates:
1) Control template: How a control is rendered and behaves by specifying the visual structure and behavioral aspects.
2) Data template: To specify the visualization of data objects.
3) Hierarchical data template: Used over hierarchical structure like TreeView and Menu.
 
What is Difference between IQueryable vs. IEnumerable in terms of LINQ to SQL queries?
The major difference between the queries is the first one doesn't contain the TOP clause to get the first record but the second one makes use of TOP to get the first record.

The major difference is that IEnumerable will enumerate all elements, while IQueryable will enumerate elements (or even do other things) based on a query. In the case of the IQueryable, the LINQ query gets used by IQueryProvider which must be interpreted or compiled in order to get the result. I.e., the extension methods defined for IQueryable take Expression objects instead of Func objects (which is what IEnumerable uses), meaning the delegate it receives is an expression tree instead of a method to invoke. IEnumerable is great for working with in-memory collections, but IQueryable allows for a remote data source, like a database or web service.
 
What is Message Exchange Patterns?
MEP stands for Message Exchange Pattern. In WCF we are creating services. What does a service do for us? A service does some task on behalf of us or sends a response back from our request. All such communications are done using messages. We send some message as a request and get a message as a response from the service.
WCF supports three types of MEPs:
1. Request / Response
2. One-Way
3. Duplex

The Request / Response MEP are used in most cases, because some kind of acknowledgement is required. In our case if the client gets TransactionId back at the time of changing the status, he can query further with this TransactionId. So acknowledgement is mandatory.

Ref. http://www.c-sharpcorner.com/UploadFile/db2972/wcf-message-exchange-patterns-day-3/
 
 
 
What is Virtual Method in .Net?

By declaring base class function as virtual, we allow the function to be overridden in any of derived class.

Example of Virtual Method in .Net:

Class parent
{
virtual void hello()
{ Console.WriteLine(“Hello from Parent”); }
}

Class child : parent
{
override void hello()
{ Console.WriteLine(“Hello from Child”); }
}

static void main()
{
parent objParent = new child();
objParent.hello();
}

//Output
Hello from Child.
 
What is a Delegate?
 Delegate is a type which holds the method(s) reference in an object. It is also referred to as a type safe function pointer.
Advantages
-Encapsulating the method's call from caller
-Effective use of delegate improves the performance of application
-Used to call a method asynchronously

Example:  public delegate int mydelegate(int delvar1,int delvar2)
public delegate double Delegate_Prod(int a,int b);
class Class1
{
    static double fn_Prodvalues(int val1,int val2)
    {
        return val1*val2;
    }
    static void Main(string[] args)
    {
        //Creating the Delegate Instance
        Delegate_Prod delObj = new Delegate_Prod(fn_Prodvalues);
        Console.Write("Please Enter Values");
        int v1 = Int32.Parse(Console.ReadLine());
        int v2 = Int32.Parse(Console.ReadLine());
        //use a delegate for processing
        double res = delObj(v1,v2);
        Console.WriteLine ("Result :"+res);
        Console.ReadLine();
    }
}
 
Asp.net Page Life Cycle: http://msdn.microsoft.com/en-IN/library/ms178472(v=vs.80).aspx
 
What is Encapsulation?

Encapsulation is one of the fundamental principles of object-oriented programming.
Encapsulation is a process of hiding all the internal details of an object from the outside world
Encapsulation is the ability to hide its data and methods from outside the world and only expose data and methods that are required
Encapsulation is a protective barrier that prevents the code and data being randomly accessed by other code or by outside the class
Encapsulation gives us maintainability, flexibility and extensibility to our code.
Encapsulation makes implementation inaccessible to other parts of the program and protect from whatever actions might be taken outside the function or class.
Encapsulation provides a way to protect data from accidental corruption
Encapsulation hides information within an object
Encapsulation is the technique or process of making the fields in a class private and providing access to the fields using public methods
Encapsulation gives you the ability to validate the values before the object user change or obtain the value
Encapsulation allows us to create a "black box" and protects an objects internal state from corruption by its clients.
 
What is Multicast Delegate?
It is a delegate which holds the reference of more than one method.
Multicast delegates must contain only methods that return void, else there is a run-time exception.
 
What is Polymorphism?
Polymorphism means same operation may behave differently on different classes.
Example of Compile Time Polymorphism: Method Overloading
Example of Run Time Polymorphism: Method Overriding

Example of Compile Time Polymorphism

Method Overloading
- Method with same name but with different arguments is called method overloading.
- Method Overloading forms compile-time polymorphism.
- Example of Method Overloading:
class A1
{
void hello()
{ Console.WriteLine(“Hello”); }

void hello(string s)
{ Console.WriteLine(“Hello {0}”,s); }
}


Example of Run Time Polymorphism

Method Overriding
- Method overriding occurs when child class declares a method that has the same type arguments as a method declared by one of its superclass.
- Method overriding forms Run-time polymorphism.
- Note: By default functions are not virtual in C# and so you need to write “virtual” explicitly. While by default in Java each function are virtual.
- Example of Method Overriding:
Class parent
{
virtual void hello()
{ Console.WriteLine(“Hello from Parent”); }
}

Class child : parent
{
override void hello()
{ Console.WriteLine(“Hello from Child”); }
}

static void main()
{
parent objParent = new child();
objParent.hello();
}
//Output
Hello from Child.

What is an Abstract Class?

An abstract class is a special kind of class that cannot be instantiated. So the question is why we need a class that cannot be instantiated? An abstract class is only to be sub-classed (inherited from). In other words, it only allows other classes to inherit from it but cannot be instantiated. The advantage is that it enforces certain hierarchies for all the subclasses. In simple words, it is a kind of contract that forces all the subclasses to carry on the same hierarchies or standards.

What is an Interface?

An interface is not a class. It is an entity that is defined by the word Interface. An interface has no implementation; it only has the signature or in other words, just the definition of the methods without the body. As one of the similarities to Abstract class, it is a contract that is used to define hierarchies for all subclasses or it defines specific set of methods and their arguments. The main difference between them is that a class can implement more than one interface but can only inherit from one abstract class. Since C# doesn’t support multiple inheritance, interfaces are used to implement multiple inheritance.

Both Together

When we create an interface, we are basically creating a set of methods without any implementation that must be overridden by the implemented classes. The advantage is that it provides a way for a class to be a part of two classes: one from inheritance hierarchy and one from the interface.
When we create an abstract class, we are creating a base class that might have one or more completed methods but at least one or more methods are left uncompleted and declared abstract. If all the methods of an abstract class are uncompleted then it is same as an interface. The purpose of an abstract class is to provide a base class definition for how a set of derived classes will work and then allow the programmers to fill the implementation in the derived classes.
There are some similarities and differences between an interface and an abstract class that I have arranged in a table for easier comparison:
Feature Interface Abstract class
Multiple inheritance A class may inherit several interfaces. A class may inherit only one abstract class.
Default implementation An interface cannot provide any code, just the signature. An abstract class can provide complete, default code and/or just the details that have to be overridden.
Access Modfiers An interface cannot have access modifiers for the subs, functions, properties etc everything is assumed as public An abstract class can contain access modifiers for the subs, functions, properties
Core VS Peripheral Interfaces are used to define the peripheral abilities of a class. In other words both Human and Vehicle can inherit from a IMovable interface. An abstract class defines the core identity of a class and there it is used for objects of the same type.
Homogeneity If various implementations only share method signatures then it is better to use Interfaces. If various implementations are of the same kind and use common behaviour or status then abstract class is better to use.
Speed Requires more time to find the actual method in the corresponding classes. Fast
Adding functionality (Versioning) If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method. If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly.
Fields and Constants No fields can be defined in interfaces An abstract class can have fields and constrants defined
 
What is anonymous method in c#?
An anonymous method is inline unnamed method in the code. It is created using the delegate keyword and doesn’t required name and return type. an anonymous method has only body without name, optional parameters and return type.
An anonymous method behaves like a regular method and allows us to write inline code in place of explicitly named methods.
 Anonmous Method to Delegate
  1. delegate int MathOp(int a, int b);
  2. public static void Main() { //statements
  3. MathOp op = delegate(int a, int b) { return a + b; };
  4. int result = MathOp(13, 14);
  5. //statements
  6. }
Anonymous Mehtod as Event Handler
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. // Click Event handler using Regular method
  4. btnCancel.Click += new EventHandler(ClickEvent);
  5. // Click Event handler using Anonymous method
  6. btnSubmit.Click += delegate { lblmsg.Text="Submit Button clicked using Anonymous method"; };
  7. }
  8. protected void ClickEvent(object sender, EventArgs e)
  9. {
  10. lblmsg.Text="Cancel Button clicked using Regular method";
  11. }

http://www.dotnet-tricks.com/Tutorial/csharp/40ID180612-C-Sharp-Anonymous-Method.html
 
What is Extension Method?
Using extension methods, you can use your new methods as a part of INT(or Other Class) class in .NET.
An extension method is a special kind of static method that allows you to add new methods to existing types without creating derived types.
The extension methods are called as if they were instance methods from the extended type, For example: x is an object from int class and we called it as an instance method in int class.
namespace ConsoleApplication1 
{ 
    class Program 
    { 
        static void Main(string[] args) 
        { 
            int x = 3; 
            Console.WriteLine(x.factorial()); 
            Console.ReadLine(); 
        } 
    } 
    public static class MyMathExtension 
    { 
        public static int factorial(this int x) 
        { 
            if (x <= 1) return 1; 
            if (x == 2) return 2; 
            else 
                return x * factorial(x - 1); 
        } 
    }
}
  • It is important to note that extension methods can't access the private methods in the extended type.
  • This keyword has to be the first parameter in the extension method parameter list. 
  • Extension methods are used extensively in C# 3.0 and further version specially for LINQ extensions in C#, for example:
  • int[] ints = { 10, 45, 15, 39, 21, 26 }; var result = ints.OrderBy(g => g); 
 
What is Inheritance?
The process of sub-classing a class to extend its functionality is called Inheritance.
It provides idea of reusability.

What is Order of Constructor execution in Inheritance?
constructors are called in the order from the top to the bottom (parent to child class) in inheritance hierarchy.

What is Order of Destructor execution in Inheritance?
The destructors are called in the reverse order, i.e., from the bottom to the top (child to parent class) in the inheritance hierarchy.

What are Sealed Classes in C#?
The sealed modifier is used to prevent derivation from a class. A compile-time error occurs if a sealed class is specified as the base class of another class. (A sealed class cannot also be an abstract class)

Does C# supports Multiple Inheritance?
Multiple inheritance of classes is not allowed in C#.

How do I achieve Multiple Inheritance in C#?
In C# you can implements more than one interface, thus multiple inheritance is achieved through interface.

Which is the ultimate base class for all the classes in .Net?
Sytem.Object, The Object class defined in the System namespace is implicitly the ultimate base class of all the classes in C# (and the .NET framework)

Does structure in C# supports inheritance?
Structures (struct) in C# does not support inheritance, it can only implements interfaces.
 

WCF Types of Binding

BasicHttpBinding

  • It is suitable for communicating with ASP.NET Web services (ASMX)-based services that comfort with WS-Basic Profile conformant Web services.
  • This binding uses HTTP as the transport and text/XML as the default message encoding.
  • Security is disabled by default
  • This binding does not support WS-* functionalities like WS- Addressing, WS-Security, WS-ReliableMessaging
  • It is fairly weak on interoperability.

WSHttpBinding

  • Defines a secure, reliable, interoperable binding suitable for non-duplex service contracts.
  • It offers lot more functionality in the area of interoperability.
  • It supports WS-* functionality and distributed transactions with reliable and secure sessions using SOAP security.
  • It uses HTTP and HTTPS transport for communication.
  • Reliable sessions are disabled by default.

WSDualHttpBinding

This binding is same as that of WSHttpBinding, except it supports duplex service. Duplex service is a service which uses duplex message pattern, which allows service to communicate with client via callback.
In WSDualHttpBinding reliable sessions are enabled by default. It also supports communication via SOAP intermediaries.

WSFederationHttpBinding

This binding support federated security. It helps implementing federation which is the ability to flow and share identities across multiple enterprises or trust domains for authentication and authorization. It supports WS-Federation protocol.

NetTcpBinding

This binding provides secure and reliable binding environment for .Net to .Net cross machine communication. By default it creates communication stack using WS-ReliableMessaging protocol for reliability, TCP for message delivery and windows security for message and authentication at run time. It uses TCP protocol and provides support for security, transaction and reliability.

NetNamedPipeBinding

This binding provides secure and reliable binding environment for on-machine cross process communication. It uses NamedPipe protocol and provides full support for SOAP security, transaction and reliability. By default it creates communication stack with WS-ReliableMessaging for reliability, transport security for transfer security, named pipes for message delivery and binary encoding.

NetMsmqBinding

  • This binding provides secure and reliable queued communication for cross-machine environment.
  • Queuing is provided by using MSMQ as transport.
  • It enables for disconnected operations, failure isolation and load leveling

NetPeerTcpBinding

  • This binding provides secure binding for peer-to-peer environment and network applications.
  • It uses TCP protocol for communication
  • It provides full support for SOAP security, transaction and reliability.

Blog Archive

Contributors