struct is a value type while interface is a reference type.
A cast from struct to an interface is a boxing.
using System;
interface Printable
{
void print();
}
struct Rectangle : Printable
{
public void print()
{
Console.WriteLine("rectangle");
}
}
class Test
{
static void Main()
{
Printable p = new Rectangle(); // boxing
p.print();
}
}
The output:
rectangle
| ww_w.__j_av___a_2_s___.c__o_m_ | Contact Us |
| Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
| All other trademarks are property of their respective owners. |