我有两个多字节,都是IEnumerables,我想比较它们.
string[] names1 = { "tom", "dick", "harry" };
string[] names2 = { "tom", "dick", "harry", "harry"};
string[] names3 = { "tom", "dick", "harry", "sally" };
string[] names4 = { "dick", "harry", "tom" };
希望names1 == names4返回true(并且self == self显然返回true)
但是所有其他组合都返回false.
什么是最有效的方式?这些可以是大量复杂对象.
我看着做:
var a = name1.orderby<MyCustomType, string>(v => v.Name);
var b = name4.orderby<MyCustomType, string>(v => v.Name);
return a == b;
我的Google-Jitsu让我失望了.问题在标题中...... T[,]和之间有什么区别T[*,*]?我正在寻找一个2,2/2部分答案:
Layman(或超级建筑师)的简明英语解释与示例代码.
链接到这种区别的正式文件.
额外奖励:指向定义此内容的C#4规范中的子部分和页码.(它不在第12节"阵列")
我在这里得到了这个概念.
因此,事实证明并非创建的所有阵列等.多维数组可以具有非零下限.请参阅Excel PIA的Range.Value属性object[,] rectData = myRange.Value;
我需要将这些数据转换为锯齿状数组.我第一次尝试下面的复杂气味.有什么优化建议吗?它需要处理下限可能不为零的一般情况.
我有这个ex方法:
public static T[][] AsJagged<T>( this T[,] rect )
{
int row1 = rect.GetLowerBound(0);
int rowN = rect.GetUpperBound(0);
int col1 = rect.GetLowerBound(1);
int colN = rect.GetUpperBound(1);
int height = rowN - row1 + 1;
int width = colN - col1 + 1;
T[][] jagged = new T[height][];
int k = 0;
int l;
for ( int i = row1; i < row1 + height; i++ )
{
l = 0;
T[] …Run Code Online (Sandbox Code Playgroud) 是否可以在ClassCleanup中嵌套TestMethods并让它们作为TestMethods而不是常规方法调用运行/行为?
我有一个TestClass来测试我创建的AppMngr类来管理进程.我测试打开/关闭应用程序的能力(例如MyNotepadMngrClass.Open()和... Close()).我还有几个在该过程中工作的类(例如MyNotepadWorkerClass.WriteLine()或... DoSomething()).在测试其他类时,我需要启动记事本并在完成后关闭它.ClassInitialize/ClassCleanup是显而易见的地方.但我想确认记事本已关闭.
所以我为Close操作创建了一个静态[TestMethod].我在MyNotepadWorkerTestClass中从ClassCleanup调用它.它执行关闭操作很好.但是如果我添加类似的东西--Assert.IsFalse(true); - 对于我的close方法的主体,测试运行不会失败.
如果我想要做的事情从根本上是错误的,请告诉我.感谢任何你可以给予帮助.
PS Hey TestStand伙计们,我正在寻找RunSelectedStep期间的Setup/Ceanup行为.TestDriven.NET给了我RunSelectedStep.那么如何在ClassInitialize和ClassCleanup中捕获失败.
我可能会遗漏一些明显的东西......
但是当我学会欣赏IoC和ctor注入的荣耀时,我很难将它与对象图序列化协调起来.这两种模式是否兼容?为什么或者为什么不)?
假设有:
public class Foo
{
#region invariants
private readonly List<IBar> _bars;
private readonly Guid _id;
#endregion
public Foo( List<IBar> bars, Guid id )
{
_bars = bars.CannotBeNull("bars");
_id = id.CannotBeNull("id");
}
public List<IBar> Bars { get { return _bars; } }
//some other state I want serialized
}
public static class Ex
{
public static T CannotBeNull<T>( this T obj, string paramName = "" )
{
if ( null == obj ) throw new ArgumentNullException(paramName);
return obj;
} …Run Code Online (Sandbox Code Playgroud) architecture dependency-injection ninject inversion-of-control constructor-injection
我想使用的this关键字或类似的东西typeof(this)在where我的通用接口的限制,但显然这不是正确的(没有编译).有一种光滑的方式可以做到这一点,我不知道吗?
interface IParent<TChild> where TChild : IChildOf<typeof(this)>
{
void AddRange(TChild children){}
}
interface IChildOf<TParent> : IDisposable
{
TParent Parent { get; }
}
Run Code Online (Sandbox Code Playgroud)
或者我必须这样做
interface IParent<TChild, T2> where TChild : IChildOf<T2>
Run Code Online (Sandbox Code Playgroud)
并且只知道T2将是实现接口的类?
c# ×5
arrays ×2
architecture ×1
c#-4.0 ×1
generics ×1
linq ×1
ninject ×1
set ×1
unit-testing ×1
where ×1
where-clause ×1