public class Foo
{
public void DoFoo()
{
int x;
var coll = TheFunc("bar", out x);
}
public Func<string, int, ICollection<string>> TheFunc { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
错误:"参数2不应与'out'关键字一起传递."
public class Foo
{
public void DoFoo()
{
int x;
var coll = TheFunc("bar", out x);
}
public Func<string, out int, ICollection<string>> TheFunc { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
错误:"无效的方差修饰符.只能将接口和委托类型参数指定为变体."
如何在此函数中获取out参数?
刚刚注意到这不起作用:
var dict = new Dictionary<int, XElement>();
XContainer element;
//...
if (dict.TryGetValue(idx, out element)) { //...
Run Code Online (Sandbox Code Playgroud)
然后我尝试了这个:
class A { }
class B : A { }
class Program {
static void Main() {
A a;
a = Ret(); // no error, ok
Ref(ref a); // compiler error, ok...
Out(out a); // compiler error, lolwut?!
}
static B Ret() { return null; }
static void Ref(ref B b) { }
static void Out(out B b) { b = null; } …Run Code Online (Sandbox Code Playgroud) 有没有一种方法可以使用最小起订量对方法进行顺序调用返回不同的out参数?获取该方法的快速示例:
public void OutputANumber(out int number)
Run Code Online (Sandbox Code Playgroud)
输出 1,然后输出 2 (忽略它可能返回的事实int,这只是一个示例,不是真正的代码)。
int number = 1;
mock.Setup(n => n.OutputANumber(out number));
number = 2;
mock.Setup(n => n.OutputANumber(out number));
Run Code Online (Sandbox Code Playgroud)
不起作用,因为第二个设置会覆盖第一个设置,同样,SetupSequence仅允许顺序返回。
我采用了棱角分明4 NG-引导如图所示这里
我试图让模态滑动和淡入/淡出,但没有提供示例来做到这一点。我已经在这个线程上尝试了两种解决方案,例如使用自定义类'slideInUp'像这样打开我的模式 -
this.modalService.open(content, {centered: true, backdrop: 'static', keyboard: false, windowClass:'slideInUp'}).result.then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
})Run Code Online (Sandbox Code Playgroud)
并为“slideInUp”添加 css -
.slideInUp {
-webkit-animation-name: slideInUp;
animation-name: slideInUp;
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
@-webkit-keyframes slideInUp {
0% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
visibility: visible;
}
100% {
-webkit-transform: translateY(0);
transform: translateY(0);
}
}
@keyframes slideInUp {
0% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
visibility: visible; …Run Code Online (Sandbox Code Playgroud)我有菜单活动和从菜单启动的游戏活动.我发起游戏活动的一些(大多数时间); 所有输入都挂起几个(最多10个小时)秒然后在超速速度下播放,而我在logcat中得到这个:
11-20 18:24:27.873: WARN/WindowManager(2473): Key dispatching timed out sending to southgrove.game/southgrove.game.Game
11-20 18:24:27.873: WARN/WindowManager(2473): Previous dispatch state: {{KeyEvent{action=1 code=4 repeat=0 meta=0 scancode=28 mFlags=8} to Window{4866c7a0 southgrove.game/southgrove.game.Game paused=false} @ 1290273811209 lw=Window{4866c7a0 southgrove.game/southgrove.game.Game paused=false} lb=android.os.BinderProxy@484e8a58 fin=false gfw=true ed=true tts=0 wf=false fp=false mcf=Window{4866c7a0 southgrove.game/southgrove.game.Game paused=false}}}
11-20 18:24:27.873: WARN/WindowManager(2473): Current dispatch state: {{null to Window{4833d500 southgrove.game/southgrove.game.Game paused=false} @ 1290273867876 lw=Window{4833d500 southgrove.game/southgrove.game.Game paused=false} lb=android.os.BinderProxy@485487b0 fin=false gfw=true ed=true tts=0 wf=false fp=false mcf=Window{4833d500 southgrove.game/southgrove.game.Game paused=false}}}
Run Code Online (Sandbox Code Playgroud)
菜单活动:
package southgrove.game;
import southgrove.game.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog; …Run Code Online (Sandbox Code Playgroud) 我正在使用Linux Ubuntu中的opencv中的以下代码.x_captured和y_captured是"int"类型向量.两个向量的大小是18.
for (int i=0;i<=x_captured.size();i++)
{
for (int j=0;j<=y_captured.size();j++)
{
if (i!=j)
{
if (((x_captured.at(j)-x_captured.at(i))<=2) &&
((y_captured.at(j)-y_captured.at(i))<=2))
{
consecutive=consecutive+1;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是当i = 0且j = 18之后,它会抛出以下错误:
在抛出'std :: out_of_range'的实例后调用终止what():vector :: _ M_range_check
可能重复:
C# - 引用类型仍然需要通过ref?
class OutReturnExample
{
static void Method(out int i, out string s1, out string s2)
{
i = 44;
s1 = "I've been returned";
s2 = null;
}
static void Main()
{
int value;
string str1, str2;
Method(out value, out str1, out str2);
// value is now 44
// str1 is now "I've been returned"
// str2 is (still) null;
}
Run Code Online (Sandbox Code Playgroud)
我是C#的新手并且学习了修饰符.我在MSDN上看到了这个片段.
我理解out这对于int原始变量很有用,但对于字符串变量,即使没有out修饰符,引用也会传递给被调用的方法,对吧?
假设我们有一个方法:
public void SomeMethod(out string[] someArray) { // ... }
Run Code Online (Sandbox Code Playgroud)
有没有办法做类似的事情:
IEnumerable<string> result;
SomeMethod(out result);
Run Code Online (Sandbox Code Playgroud)
编辑:重点是,我不想将out值绑定到string[],我希望代码能够工作,即使方法声明被更改为SomeMethod(out List<string> outputValue).
我正在尝试为具有参数的方法编写单元测试.我的方法特别是我的自定义对象的TryParse方法.我在Visual Studio 2013中使用.NET 4.5/5.这使我可以使用PrivateType对象完全实现私有/内部和静态对象.似乎逃避我的一件事是如何测试out参数,因为我不能在InvokeStatic方法中使用this关键字.我正在寻找适当的解决方案来测试这种架构设计.
TryParse的使用是TypeConverter进程的一部分,如WebAPI参数绑定帖子中所述.作者:Mike Wilson
public class MyFilter
{
public string Field { get; set; }
//... removed for brevity
internal static bool TryParse(string sourceValue, out MyFilter filter)
{
//... removed for brevity
}
}
public class MyFilterTests
{
[TestMethod]
[TestCategory("TryParse")]
public void TryParseWithTitleOnly()
{
var stringSource = "{field:'DATE.FIELD'}";
MyFilter tryParseOut = null;
var target = new PrivateType(typeof(MyFilter));
var tryParseReturn = target.InvokeStatic("TryParse", stringSource, tryParseOut);
var expectedOut = new MyFilter()
{
Field = "DATE.FIELD"
};
Assert.IsTrue((bool)tryParseReturn);
Assert.AreEqual(expectedOut, tryParseOut);
} …Run Code Online (Sandbox Code Playgroud) 来自https://blogs.msdn.microsoft.com/dotnet/2017/03/09/new-features-in-c-7-0/:
我们允许"丢弃"作为输出参数,以_的形式,让你忽略你不关心的参数:
p.GetCoordinates(out var x, out _); // I only care about x
Run Code Online (Sandbox Code Playgroud)
请考虑以下代码:
void Foo(out int i1, out int i2)
{
i1 = 1;
i2 = 2;
}
int _;
Foo(out var _, out _);
Console.WriteLine(_); // outputs 2
Run Code Online (Sandbox Code Playgroud)
问题:
为什么在此上下文中输出"discard"out参数?
此外,不应该有"已定义的范围"错误out var _?
int i;
Foo(out var i, out i);
Console.WriteLine(i); // Error: A local variable or function named 'i'
// is already defined in this scope
Run Code Online (Sandbox Code Playgroud)