实现接口和访问方法

时间:2015-07-10 09:27:54

标签: c# asp.net interface

public partial class shoppingCart : ISecurisable
{
    public void Deactivate() 
    {
        shoppingCartid = null;
        IsActive = false;
        foreach (var shoppingCartDetails in Childs)
        {
            shoppingCartDetails.ParentId = ParentId;
        }
    }
}

在课程中实现了ISecurisable后,如何访问Deactivate()方法。

2 个答案:

答案 0 :(得分:2)

首先创建ShoppingCart - 类

的实例
ShoppingCart cart = new ShoppingCart();

现在调用方法

cart.Deactivate();

答案 1 :(得分:0)

  

您可以使用此表单

ISecurisable shoppingCart = new shoppingCart();
shoppingCart.Deactivate();

public interface ISecurisable
{
    void Deactivate();
}

public partial class shoppingCart : ISecurisable
{
     public void Deactivate()
     {
         shoppingCartid = null;
         IsActive = false;
         foreach (var shoppingCartDetails in Childs)
         {
            shoppingCartDetails.ParentId = ParentId;
         }
     }
}