标签: interface

C#:实现接口的类是否包含接口外的方法?

非常简单的问题.我知道在java中你可以,但在C#中可以吗?

c# interface

-7
推荐指数
1
解决办法
316
查看次数

实现ac#接口

我有一个名为myResult的dataTable,它有两列Process和ParentProcess,我试图把它放到一个Ienumerable类型中,所以我可以用Json.net序列化它.

原帖是这里的:

现在我到了这一点,我有这个界面:

namespace myFirstCProgramIn2013
    {
        public interface Interface1 : IEnumerable
        {
            string Process { get; set; }
            string ParentProcess { get; set; }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我在这个类中实现了它:

public class myArray : Interface1
{

    public string Process
    {
        get
        {
            throw new NotImplementedException();
        }
        set
        {
            throw new NotImplementedException();
        }
    }

    public string ParentProcess
    {
        get
        {
            throw new NotImplementedException();
        }
        set
        {
            throw new NotImplementedException();
        }
    }

    public System.Collections.IEnumerator GetEnumerator()
    {
        throw new NotImplementedException();
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我尝试使用此类使用以下代码将myResult分配给它:

   List<Interface1> recordList = …
Run Code Online (Sandbox Code Playgroud)

c# datatable interface

-7
推荐指数
1
解决办法
98
查看次数

在java中实现接口

我已经声明了这个界面:

public interface Filter 
{   
/**
  Determines whether to accept an object.
  @param x the object to be filtered
  @return true to accept an object, false otherwise
*/
boolean accept(Object x);   
}
Run Code Online (Sandbox Code Playgroud)

所以现在我需要做的是将它与已经在类中声明和实现的另一个接口一起实现.所以我的问题是我是否可以用这种方式在同一个类中实现这两个接口.

public class DataSet implements Measurer, implements Filter{
 ......
 }

or

 public class DataSet implements Measurer, Filter{
 .....
 }
Run Code Online (Sandbox Code Playgroud)

谢谢

java interface

-8
推荐指数
1
解决办法
129
查看次数

Java接口和抽象类

我们今天进行了Java测试,对正确的答案进行了激烈的讨论.你能用一个简单的解释帮我找到正确的答案吗?

问题:这个Java代码有什么问题?

abstract class Fluffy {
}

interface Animal {
}

class Cat extends Fluffy implements Animal {
}

class Dog extends Fluffy implements Animal {
}
Run Code Online (Sandbox Code Playgroud)

选项

  1. Animal必须是一个抽象类,Fluffy必须是一个接口
  2. 蓬松必须实施动物
  3. 动物必须是抽象类
  4. 蓬松必须是一个界面

您只能选择一个答案

java abstract-class interface

-8
推荐指数
1
解决办法
103
查看次数

C# - 无法创建抽象类或接口的实例

Cannot create an instance of the abstract class or interface在C#教程中收到错误.

它在这条线上失败了: result = new Account(nameText, addressText, balance);

这是我的班级:

public abstract class Account : IAccount
{
    //---------------------------------------------------------------
    // Constructor
    //---------------------------------------------------------------
    public Account(string inName, string inAddress, decimal inBalance)
    {
        name = inName;
        address = inAddress;
        balance = inBalance;
    }
    public Account(string inName, string inAddress) :
        this(inName, inAddress, 0)      // 'this ties this alternate constructor back to the original constructor (directly above)
    {
    }
    public Account(string inName) :     // 'this ties …
Run Code Online (Sandbox Code Playgroud)

c# oop interface class

-9
推荐指数
1
解决办法
9161
查看次数

TypeScript 中特定类型的切换不起作用

data我试图在接口中实现常量,但为什么在 switch 情况下访问时会出错?

如果我只使用stringininterface而不是常量,APP_STATUS那么它就可以正常工作。

例子:

// Gives an error
interface InconsistenciesData {
  type: typeof APP_STATUS.INCONSISTENCIES;
  data: Inconsistency[];
}

// Works fine
interface InconsistenciesData {
  type: 'INCONSISTENCIES';
  data: Inconsistency[];
}
Run Code Online (Sandbox Code Playgroud)

下面是我的代码片段。

文件类型.ts

export const APP_STATUS = {
  CONFIRMED: 'CONFIRMED',
  INCONSISTENCIES: 'INCONSISTENCIES',
  SUCCESS: 'SUCCESS',
  ERROR: 'ERROR',
  LOADING: 'LOADING',
  OK: 'OK'
}

interface InconsistenciesLoading {
  type: typeof APP_STATUS.LOADING;
}

interface InconsistenciesError {
  type: typeof APP_STATUS.ERROR;
}

interface InconsistenciesSuccess {
  type: typeof APP_STATUS.SUCCESS;
}

interface InconsistenciesData …
Run Code Online (Sandbox Code Playgroud)

interface switch-statement typescript

-9
推荐指数
1
解决办法
721
查看次数