我认为这可能是一个非常简单的问题,但我还没有弄清楚.如果我有一个像这样的二维数组:
int[,] matris = new int[5, 8] {
{ 1, 2, 3, 4, 5,6,7,8 },
{9,10,11,12,13,14,15,16},
{ 17,18,19,20,21,22,23,24 },
{ 25,26,27,28,29,30,31,32 },
{ 33,34,35,36,37,38,39,40 },
};
Run Code Online (Sandbox Code Playgroud)
和一个for循环,像这样:
for (int r = 0; r < 5; r++)
{
for (int j = 0; j < 8; j++)
Console.Write("{0} ", matris[r, j]);
Console.WriteLine();
}
Run Code Online (Sandbox Code Playgroud)
所以使用这段代码我打印出多维数组.但是如何打印阵列的转置?
我有一个抽象的基类:
abstract class Foo
{
virtual void DoSomeStuff()
{
//Do Some Stuff
}
abstract void DoSomeCrazyStuff();
}
Run Code Online (Sandbox Code Playgroud)
另一个抽象类派生自:
abstract class Bar : Foo
{
abstract override void DoSomeStuff();
abstract override void DoSomeCrazyStuff();
}
Run Code Online (Sandbox Code Playgroud)
我理解你为什么要抽象覆盖DoSomeStuff()- 它需要一个新的实现进一步派生类.但我无法弄清楚你为什么要抽象覆盖DoSomeCrazyStuff().据我所知,这是多余的 - 我很确定删除它会产生零负面影响.
是否有一些用例,抽象覆盖在抽象上有用吗?如果没有,为什么没有编译器警告通知我,我写的东西什么都没做?
我正在尝试使用Matlab通过串口发送TTL信号.我只需要向设备发送1个值,因此它应该是一个非常简单的过程.我的问题是我不知道我是不是正确地做了这个或者设备是不是处理信号.我的代码是这样的:
mysignal = serial('com1');
fopen(mysignal);
fwrite(mysignal,1);
Run Code Online (Sandbox Code Playgroud) 任何人都可以解释一下,为什么我必须使用这种代码模式?
// Create the array to store the CDs.
CD[] cdLibrary = new CD[20];
// Populate the CD library with CD objects.
for (int i=0; i<20; i++)
{ cdLibrary[i] = new CD(); }
Run Code Online (Sandbox Code Playgroud)
我无法理解为什么在调用时不会发生数组中对象的初始化new CD[20].好像我在编写多余的代码.可以跳过其中一个步骤吗?
我有两个类:Foo和FooBar.FooBar来自Foo.我有一个工厂类,给定参数,决定实例化和返回哪个对象.
所以我希望有单元测试来验证我的工厂类是否正常工作并返回正确的实例.
对于FooBar来说这有点干净:
[Test]
public void FooBarFactoryTest()
{
var testObj = FooFactory(paramsForFooBarOnly);
Assert.IsInstanceOf<FooBar>(testObj);
}
Run Code Online (Sandbox Code Playgroud)
但对于Foo来说,它相当混乱:
[Test]
public void FooFactoryTest()
{
var testObj = FooFactory(paramsForFooOnly);
Assert.IsInstanceOf<Foo>(testObj); //An instance of FooBar would pass this assert
Assert.IsNotInstanceOf<FooBar>(testObj); //Can't have just this assert.
}
Run Code Online (Sandbox Code Playgroud)
有没有什么办法可以重新编写第二个测试来遵循"每次测试一个断言?"的范例.优选地,我还希望进行测试以解释Foo或FooBar的潜在额外推导.
如果可能的话,请帮助我理解:
var regexMatch = Regex.Match(inputString, "(\S*\d+\S*|\d)+");
if (regexMatch.Value == String.Empty)
{
return null;
}
else
{
var trimmedString = regexMatch.Value.Trim();
if(trimmmedString != regexMatch.Value)
{
//Is there any value for inputString that makes this reachable?
}
}
Run Code Online (Sandbox Code Playgroud)