Let's say I have 2 interfaces defined like so:
public interface ISkuItem
{
public string SKU { get; set; }
}
public interface ICartItem : ISkuItem
{
public int Quantity { get; set; }
public bool IsDiscountable { get; set; }
}
When I go to implement the interface in C#, VS produces the following templated code:
public class CartItem : ICartItem
{
#region ICartItem Members
public int Quantity { get {...} set {...} }
public bool IsDiscountable { get {...} set {...} }
#endregion
#region ISkuItem Members
public string SKU { get {...} set {...} }
#endregion
}
In VB.NET, the same class is built out like so:
Public Class CartItem
Implements ICartItem
Public Property IsDiscountable As Boolean Implements ICartItem.IsDiscountable
'GET SET'
End Property
Public Property Quantity As Integer Implements ICartItem.Quantity
'GET SET'
End Property
Public Property SKU As String Implements ISkuItem.SKU
'GET SET'
End Property
End Class
VB.NET explicitly requires you to add Implements IInterfaceName.PropertyName
after each property that gets implemented whereas C# simply uses region
s to indicate which properties and methods belong to the interface.
Interestingly in VB.NET, on the SKU
property, I can specify either Implements ISkuItem.SKU
or Implements ICartItem.SKU
. Although the template built by VS defaults to ISkuItem
, I can also specify ICartItem
if I want. Oddly, because C# only uses region
s to block out inherited properties, it seems that I can't explicitly specify the implementing interface of SKU
in C# like I can in VB.NET.
My question is: Is there any importance behind being able to specify one interface or another to implement properites in VB.NET, and if so, is there a way to mimic this functionality in C#? Furthermore, what is the effect of specifying one interface over another when implementing properites?