Overview of inheritance with C# : part 2

Overriding

If we create base class method to virtual and override the method of the derived class, now when we instantiate the base class object to derived class and call the method with respect to the object then method of derived class will be invoked.

Sample Code

Overview of inheritance with C# : part 1

When base class and derived class both have same method but base class's method is not virtual, and derived class's method is not overridden, then if we instantiate the object of base class to derived class and call the method with respect to the object created, the method written in base class will be invoked.

Sample code

namespace Inheritance { class Program { static void Main(string[] args) { BaseDemo bd = new DerivedDemo(); bd.PrintString(); Console.ReadLine(); } } class BaseDemo { public BaseDemo() { } public void PrintString() { Console.WriteLine("Base Demo Invoked"); } } class DerivedDemo : BaseDemo { public DerivedDemo() { } public void PrintString() { Console.WriteLine("Derived Demo Invoked"); } } }
Output
Base Demo Invoked

Compilation of above code will generate warning that
"Warning 1 'Inheritance.DerivedDemo.PrintString()' hides inherited member Inheritance.BaseDemo.PrintString()'. Use the new keyword if hiding was intended."

Binding Errors in WPF / XAML


WPF doesn’t raise exceptions to notify programmer about data binding problems. If you specify an element or a property that doesn’t exist, you won’t receive any indication; instead, the data will simply fail to appear
in the target property. At first glance, this seems like a debugging nightmare. Fortunately, WPF does output trace information that details binding failures. This information appears in Visual Studio’s Output window
when you’re debugging the application. For example, if you try to bind to a nonexistent property, you’ll
see a message like this in the Output window:

Data Trigger to Inverse the value of IsChecked Property of checkbox for binding

Many times we may require to enable / disable controls in WPF on the check state of a checkbox in the window. In XAML we want to enable our control if checkbox is checked and disable if it is unchecked, this can be done very easily by using below binding


<StackPanel Orientation="Horizontal"> <CheckBox x:Name="chkHandler" Content="Enable Controls"> </CheckBox> <TextBlock Width="50" />
<TextBox x:Name="Sample" Text="Sample Text Box" 
IsEnabled="{Binding Path=IsChecked, ElementName=chkHandler}">
</TextBox> </StackPanel>

Singleton Design Pettarn - Details Explaination

What is singleton design pattern ?

Singleton design pattern allows programmer to create only one instance for a class for whole life cycle of process. In this case if developer tries to get new instance of class, he/she will get the same instance of the class which was created once.

Way of Implementation 
To implement singleton design pattern we must have to make all the constructor of the class private, so that developers can not create new instance of the class directly (Developer will not have control to create object of class).
There must be a static  method in class which will be called by developer to obtain the singleton object.