Banner Ad

Sunday, March 16, 2014

Daily Interview Question #7: Implicit and Explicit Implementation of Interface

By Francis   Posted at   12:22 AM   OOPS interview Questions No comments

                                                   This is the most common interview question for experienced professionals.

Normally an interface can be implemented in a class in a normal way which is a implicit implementation. Sometime, we may have same method name in different interfaces. If this is the case, we need to do explicit implementation of the interface method. The main use of explicit implementation is to avoid the ambiguities between the class or method name. In order,  to do that the interface name put before that interface’s method.

 

Below example, shows the implicit and explicit implementation:

 

namespace ConsoleApplicationC
{
    // 2 interfaces with same method name
    interface IintegerAdd
    {
        void Add();
    }
    interface IfloatAdd
    {
        void Add();
        void Multiply();
    }


    // We implement Both interfaces
    class ArithmeticOperation : IintegerAdd, IfloatAdd
    {
        // Implicit  Implementation : There is no name collision so we can implement implicitly
        // NOTE : public modifier MUST here
        public void Multiply()
        {
            float a = 1.5f, b = 2.5f;
            Console.WriteLine("Float Multiplication is:" + a * b);
        }


        // Explicit Implementation :  Explicitly tell the compiler that we implement the interface IintegerAdd
        void IintegerAdd.Add()
        {
            int a = 10, b = 20;
            Console.WriteLine("Integer Addition Is:" + (a + b));
        }


        // Explicit Implementation :  Explicitly tell the compiler that we implement the interface IfloatAdd
        void IfloatAdd.Add()
        {
            float a = 1.5f, b = 2.5f;
            Console.WriteLine("Float Addition Is:" + (a + b));
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            ArithmeticOperation objA = new ArithmeticOperation();
            IintegerAdd iobj = (IintegerAdd)objA;
            iobj.Add();
            IfloatAdd fobj = (IfloatAdd)objA;
            fobj.Add();
            Console.ReadKey();
        }
    }
}


Output :


 


Integer Addition Is:30
Float Addition Is:4

Tuesday, March 11, 2014

Visual Studio Tips & Tricks - 8: Breakpoint will not currently be hit. No symbols have been loaded for this project.

By Francis   Posted at   5:50 PM   Visual Studio Tips and Tricks 2 comments

Most of the developers who are using Visual studio have encountered the above problem. As a ASP.Net Developer I have this atleast once a day. So the below are my tricks to get ride of this issue.

 

1) Just Close the VS IDE.

2) Go to Task Manager and kill the worker process. (If you are working on  ASP.Net application).

3) Go to the .Net installation folder ( Normally it should be C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files OR C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files) and clear the temp files from the temporary folder.

4) Open the solution and "Rebuild" entire solution. Now try to attach the debugger.

 

Please note that, in some machines you may have 2 framework installation, one for 32-bit and another for 64-bit. So when you go with step 3, pay close attention and make sure which .net framework was used and also which version no (either 2,3,3.5 or 4) was used by your application.

 

Hope this helps!

Saturday, March 8, 2014

Using MSCaptcha

By Francis   Posted at   9:08 PM   MSCaptcha No comments

                                    Recently, in one of my project I need a captcha for my application. Just a google search provides number of options. I need a open source solution, so I go with krisanov’s solution. I just download and try to using that on my project. However it doesn’t works fine. Just follow the instruction mention by mudasar in this url. But I have encountered several problems (that is it doesn’t display any captcha image) the when I added that into my project, which leads to write this post.

Below are the steps that I have followed:

 

1) Just download the captcha from the url.

2) Add the reference into the project by “Right Click on the Project –> Add Reference”.

3) After that you need to include the below lines into web.config file:

 

<system.web>
    <httpHandlers>
        <add verb="GET" path="CaptchaImage.aspx" type="WebControlCaptcha.CaptchaImageHandler, WebControlCaptcha"/>
    </httpHandlers>

</system.web>
<location path="CaptchaImage.aspx">
    <system.web>
        <authorization>
            <allow users="*"/>
        </authorization>
    </system.web>
</location>

 

What previously done, I have missed out entire “location” element, which is also not mentioned in the mudasar’s tutorial. I have found this solution in this asp.net forum thread.


Hope this helps to someone!

Wednesday, March 5, 2014

VisualStudio Tips & Tricks - 7 : Using Transact-SQL Editor in Visual Studio 2010

By Francis   Posted at   10:13 AM   Visual Studio Tips and Tricks No comments
                           Few months ago, when we upgrade from VSS to TFS, somehow we lost intellisense in SQLServer Management studio 2008 R2. We struggle a lot to obtain. But no luck till now. However, currently we are using Visual Studio 2010, which enriched with lot of futures.
            Instead of using SQL Server Management, what I did was open the SQL file using Visual Studio 2010. In Visual Studio, Right click on the Menu bar, from the floating menu “check” the “Transact-SQL Editor”.

image
Now we got the toolbar available in SQL to do some basic operations like connect the SQL Server, Execute the Transact SQL etc., The main benefit in this approach is the intellisense works fine with in the “Transact-SQL Editor”. So my problem solved temporary.
One of the main attraction in this feature is, we can do all basic operations with in this editor. However, I’m not at all a DBA, just a developer who used SQL server as a backend. This is more convenient way work as of now.

Hope this may help to some one!!

Tuesday, March 4, 2014

Visual Studio Tips & Tricks – 6 : Multi-Copy functionality in Visual Studio

By Francis   Posted at   12:26 PM   Visual Studio Tips and Tricks No comments

                                    Some time we may need to copy the multiple code snippets (that is we may need to copy and paste lines that are not in order) in a file and paste it in another location of the file inside Visual Studio. For example, we have 5 lines of text, what we need is to copy the 1,3 and 5 line of text and paste it on some other location. To achieve that functionality to do the following:

 

1) Copy the code snippets using Ctrl+C key combination. (That is select the line 1 and press Ctrl + C and select line 3 press Ctrl + C and so on).

2) When you paste that code press the key combination Ctrl + V + Shift key, which rotates the copied lines of text. To paste a particular selected text just press Ctrl + V.

 

Hope this helps to some one!

Connect with Us