小编Dav*_*vid的帖子

它是在c#中使用抽象类中的静态字段转换java接口的最佳选择吗?

public interface IHashStorage<T> {
    public static final float INITIAL_LOAD_FACTOR = 0.7f;
    public static final int INITIAL_CAPACITY = 149;
}
Run Code Online (Sandbox Code Playgroud)

我有上面的代码需要在c#中翻译.唯一合适的解决方案是使它成为一个抽象类.从我发现使用readonly比使用const更安全:

public abstract class IHashStorage<T>
    {
        private readonly float INITIAL_LOAD_FACTOR = (float)0.7;

        private readonly int INITIAL_CAPACITY = 149;
    }
Run Code Online (Sandbox Code Playgroud)

Java中的项目使用了Decorator模式和Proxy,从java到c#的转换可能需要使用更抽象的类(目前在java中只有接口使用)?我从理论上讲它们之间的区别但实际上在c#中我使用过抽象类更多.我不熟悉java,我想知道你如何找到完成这个任务的最佳解决方案,我的意思是转换代码时要记住的要点.

c# java abstract-class field interface

5
推荐指数
0
解决办法
143
查看次数

从java转换为c#-Covariance和Contravariance

  public interface IStorage<T> extends Iterable<T> {
        public void copyTo( IStorage<? super T> dest);
        public void copyFrom( IStorage<? extends T> src);
    }
Run Code Online (Sandbox Code Playgroud)

上面是我必须放在c#中的java代码,目前它看起来像

 interface IStorage<T>:  IEnumerable<T>
    {
     void copyTo( IStorage<? super T> dest);
     void copyFrom( IStorage<? extends T> src);}
Run Code Online (Sandbox Code Playgroud)

但是我有麻烦找到相当于它出现在函数参数中的时候,我发现了输入/输出或者接近但是它仍然不清楚.

c# java contravariance

1
推荐指数
1
解决办法
213
查看次数

标签 统计

c# ×2

java ×2

abstract-class ×1

contravariance ×1

field ×1

interface ×1