Interesting role of Polymorphism,Interface in C#

. Wednesday, February 23, 2011
2 comments

 Hi Guys This post is about implementing poylmorphism in c# and role of interface in c#

Polymorphism

Why?

Lets see by an example

public class Abstract
    {
    public  void  myfunction()
    {
    Console.Write("This is Abstract");
    }
  
}
 public class Inherited : Abstract
    {
        public override void myfunction()
        {
        Console.Write("This is Function Class");  
        }
}

 class Program
    {  
    
        static void Main(string[] args)
        {
            Abstract Abs = new Abstract();
            Abs = new Inherited();
            Abs.myfunction();
            Console.Read();
          }
  }

Now when you call this you will see the following  Output
"This is Function Class"

But with a warning:
Warning 1
'TestConsole.Function.myfunction()' hides inherited
member 'TestConsole.Abstract.myfunction()'. Use the
new keyword if hiding was intended. C:\Documents
and Settings\vivek\My Documents\Visual Studio
2008\Projects\TestConsole\TestConsole\Program.cs
23 22 TestConsole

which stated that if you inherit child class from parent class with having function of same signature the child
class function will be hided by parent class function.To avoid this hide of child class function by parent
class we need to use polymorphism.as follows:
in the abstract class use the following signature of function:
public virtual void  myfunction()

in the inherited class use the following singature of function:
public override void myfunction()

and now if you instantiate any of the class with abstract class's object it will override by inherited class function.

What is a interface in c# lets try it with example
I create a interface as follows:

interface Iabstract
    {
         void myfunction();
  
    }

Now i implement this with Inherited class as follows:
public class Inherited : Abstract, Iabstract
    {
        public override void myfunction()
        {
        Console.Write("This is Function Class");  
        }
    }

and call an instance of interface which references to inherited class in Main() as follows:
Iabstract objabc = new Inherited();

What should be the output?

"This is Function Class"

if you even remove the polymorphism mechanism from this still the interface instance will show the same output.

Why is it so? because interface is contract which calls functions of those classes on which its being implemented neither more nor less than that.

Hope you will enjoy this article...Thanks

425 data connection Error

. Monday, February 21, 2011
0 comments


If you stuck in issues like
*425 data connection can not be opened
*failed to display directory listing
or if you are unable to connect with ftpserver from ftpclient then try the following solution it will work.
1)Open settings from ftp server
2)then go into passive mode settings in left pane.
3)Now if radiobutton of default is checked then check
the next radio button to this asking for Insert the IP


Address and insert the localhost address(127.0.0.1) as shown above
4)Now click on Ok
5)your settings has been updated now
6)Now goto you ftp client and connect and it will work
Enjoy....

Note: This is understood that you have already configure users in ftp server and using its credentials and server ip address from your ftp client to connect.

OutputCache-asp.net mvc

. Saturday, February 19, 2011
0 comments


This post describes details about OuputCache

Caching : caching is mechanism in which you can store information on client side or server side or both for specified amout of time,can be understand by example that suppose you go to shop to purchase shirt now you try different different shirts and from which you only purchase one or two and checkout from shop.Nowshopkeeper has two options with shirts either he can put them back to their location or put them on customers desk from where they can choose again.benifit of the second option is that shopkeeper need not to go to take shirts which customers like and hence  shopkeeper roundtrip time reduces.The disadvantage is that if shopkeeper not put all those shirts back after a specifed amount of time then there would be burden on customer desk .Same happends with cache if you store information in cache for specified amount of time then there would be benifit that you don't need to pick the relative information again and again and hence your application's performance increases.
To use output caching in asp.net mvc use OutputCache attribute as show below with specified parameters



VaryByParams : suppose you have two pages one displays the Category and other displays its details.Now you if cache both of the pages with VaryByParams as "None",Even you click on any of the category you will see the exact same content as previous one but if you specify VaryByParams then your detail page will cache the different different selected category not that one which is being clicked first.

Location: specify the location for caching either on server side or client side or both.

As you can see i have added the Duration for 10 secs so the page will cached for 10 secs.

Note: asp.net mvc it is recommended to use this before respective action as OutputCache directive seems to bleeding over web forms. 

adding twitter feeds on blogger

.
0 comments

If you want to add twitter feeds on blogger then it is very simple just login to your tweet account and then go to this link
http://twitter.com/badges/blogger
which will look like as follows


after that click on add to blogger button and next click on add to widget button to add twitter widget as a gadget in blogger thanks so simple ...


Adding facebook like button on your blog or website

.
0 comments

Hi Guys, If you want to add Facebook Like button on your Blogger its easy just copy/paste thing.first login to your blogger account click on design and then click on edit HTML in this way you will find all of your blog's source html then find the following

in this way you are at the position where you have to put the following code to display Facebook's Like button
Paste the Facebook button code immediately below (after) it:



1<!-- Facebook Like button Start -->
2<b:if cond='data:blog.pageType != &quot;static_page&quot;'>
3<div style='float:left;padding:5px 5px 5px 0;'>
4<iframe allowTransparency='true' expr:src='&quot;http://www.facebook.com/plugins/like.php?href=&quot; + data:post.url + &quot;&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=35&quot;'frameborder='0' scrolling='no' style='border:none; overflow:hidden; width:440px; height:35px;'/>
5</div>
6</b:if>
7<!-- Facebook Like button End -->
Now you need to adjust position of button as you want the below table describes that 




Like button typeQueryValueWidth & Height
 standard like buttonlayoutstandard
W: 450px
H: 35px (80px w photos)
facebook like button countbutton_count
W: 90px
H: 20px
facebook like box countbox_count
W:55px
H: 65px
standard like button darkcolorschemedark
n.a.
standard like button recommendactionrecommend
n.a.