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,我想知道你如何找到完成这个任务的最佳解决方案,我的意思是转换代码时要记住的要点.
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)
但是我有麻烦找到相当于它出现在函数参数中的时候,我发现了输入/输出或者接近但是它仍然不清楚.