对于框架和指南的最大深度,是否有关于何时使用多级继承或在单个类中加入它们的最佳实践?
一些在Java世界中运行良好的既定实践/示例的引用在答案中会很好,因为这是从围绕Java的社区和框架的角度来看.
这两种方法有什么区别,你何时使用一种而不是另一种?
int[,] array = new int[4,3];
int length0 = array.GetLength(0);
int upperbound0 = array.GetUpperBound(0);
Run Code Online (Sandbox Code Playgroud)
MSDN说GetLength返回GetUpperBound确定最大索引的元素数量,但是由于数组是用每个索引的元素初始化的,所以这有什么不同呢?
在Java中什么时候应该抛出IllegalArgumentException什么时候InvalidParameterException?从C#背景的,我们将有一个ArgumentNullException从派生ArgumentException.如果我想在Java中实现等效ArgumentNullException/ ParameterNullException应该扩展IllegalArgumentException或InvalidParameterException?
注意:我不是试图实现一个ArgumentNullException/ ParameterNullException这只会让我更好地理解我是否可以将它们与C#框架相匹配.
如何将已创建的实例添加到MEF容器/目录中以在解析Imports时使用.我想要Unity RegisterInstance在其容器上使用该方法提供的功能.
将
int[] nums = { 2, 3, 3, 4, 2, 1, 6, 7, 10 };
var distinct = nums.Distinct();
Run Code Online (Sandbox Code Playgroud)
总是2, 3, 4, 1, 6, 7, 10按顺序返回?
什么是最好的.net计算机视觉库,最近有人用于不同的形状检测和条形码阅读,包括阅读pdf417?大多数库具有类似于Gimp和Photoshop中的图像处理功能,但不具备计算机视觉功能.目前我们正在研究Aforge和LEAD工具的组合; 任何人都知道更好的替代方案或一个可以做这两个图书馆可以合并的图书馆吗?
如果我有这样的方法:
public void Foo<T1, T2>(T1 list)
where T1 : IList<T2>
where T2 : class
{
// Do stuff
}
Run Code Online (Sandbox Code Playgroud)
如果我有:
IList<string> stringList = new List<string>();
List<object> objectList = new List<object>();
IList<IEnumerable> enumerableList = new List<IEnumerable>();
Run Code Online (Sandbox Code Playgroud)
然后编译器无法解析要选择的泛型,这会失败:
Foo(stringList);
Foo(objectList);
Foo(enumerableList);
Run Code Online (Sandbox Code Playgroud)
您必须明确指定要使用的泛型:
Foo<IList<string>, string>(stringList);
Foo<IList<object>, object>(objectList);
Foo<List<object>, object>(objectList);
Foo<IList<IEnumerable>, IEnumerable>(enumerableList);
Run Code Online (Sandbox Code Playgroud) 通常,如果我有这个:
public string Foo(string text)
{
return text.Substring(3);
}
Run Code Online (Sandbox Code Playgroud)
我会CA1062: Validate arguments of public methods从代码分析中得到一个.它可以通过修改代码来修复:
public string Foo(string text)
{
if (text == null)
throw new ArgumentNullException("text");
else if (string.IsNullEmptyOrWhiteSpace(text)
throw new ArgumentException("May not be empty or white space", "text")
else if (text.Length < 3)
throw new ArgumentException("Must be at least 3 characters long", "text");
return text.Substring(3);
}
Run Code Online (Sandbox Code Playgroud)
但现在我想使用另一种方法进行此验证:
public string Foo(string text)
{
Validator.WithArgument(text, "text").NotNullEmptyOrWhitespace().OfMinLength(3);
return text.Substring(3);
}
Run Code Online (Sandbox Code Playgroud)
因为该方法验证了参数,所以代码分析规则得到满足,但您仍然会收到CA1062警告.有没有办法抑制代码分析规则这样的情况,而不是每次都手动抑制它们或关闭特定的代码分析规则?
我想在Visual Studio 2010中添加一个编辑器,它应该类似于你为Entity Framework获得的编辑器,即你有一个可视化设计器,它将自己的配置保存到自己的文件中,然后从中生成代码.
因此,这涉及两个方面是特定文件扩展名的可视化表示,第二个是代码生成(或者代码是在文件编辑时生成还是仅在生成时生成?)
我已经完成了一些冲浪,但无法获得有关如何执行这些特定事情的任何资源(尤其是代码生成部分),任何指向正确方向的资源都可能会受到赞赏.
会是什么原因,该代码导致m_cause的0对打开的文件.找到了很多原因,将返回另一个代码,但没有理由0.
CFileException fileException;
CFile myFile;
if (myFile.Open("C:\\test\\docs\\test.txt", CFile::modeCreate | CFile::modeWrite, &fileException))
{
TRACE( "Can't open file %s, error = %u\n", "test.txt", fileException.m_cause );
}
Run Code Online (Sandbox Code Playgroud) c# ×8
java ×2
.net ×1
arrays ×1
c++ ×1
exception ×1
file-io ×1
frameworks ×1
generics ×1
inheritance ×1
linq ×1
mef ×1
plugins ×1
silverlight ×1