在jquery中执行clickout的最简单方法是什么?如果在其外部的任何位置单击div框,则隐藏div框.
我阅读了传递数组的页面使用ref和out(C#编程指南),并想知道为什么我们需要将数组参数定义为ref参数(当它已经是引用类型时).被调用函数中的更改不会反映在调用函数中吗?
使用此构造:
var dict = new Dictionary<int, string>();
var result = (dict?.TryGetValue(1, out var value) ?? false) ? value : "Default";
Run Code Online (Sandbox Code Playgroud)
我收到一个错误消息,说CS0165 use of unassigned local variable 'value'那不是我期望的。怎么value可能不确定?如果字典为null,则将返回内部语句false,这将使外部语句的值为false,返回Default。
我在这里想念什么?只是编译器无法完全评估该语句吗?还是我搞砸了?
鉴于此代码:
private void TryIt(Dictionary<int, int> myDict)
{
if (myDict?.TryGetValue(1, out int myValue) ?? false)
{
Console.Out.WriteLine(myValue); // <-- Error CS0165
}
}
Run Code Online (Sandbox Code Playgroud)
C# 编译器发出:
error CS0165: Use of unassigned local variable 'myValue'
Run Code Online (Sandbox Code Playgroud)
但当操作员跳过调用myValue时,显然无法引用。这是因为结果被转换为by 。TryGetValue()?.nullfalse?? false
换句话说,如果myDictis null,?.操作员将跳过对 的调用TryGetValue(),保持myValue未分配状态。我明白了。
但是??操作符将始终评估到 的 null 传播false,从而防止在这种情况下进入 if 块。
这在编译时很明显,那么为什么会出现错误呢?
我怀疑这可能与所有这些语法糖最终如何分解为实际的 .NET p 代码有关,但错误似乎仍然是错误的......
不使用.?运算符时,我不会收到任何错误,这是预期的:
if (myDict.TryGetValue(1, out int myValue))
{
Console.Out.WriteLine(myValue); // …Run Code Online (Sandbox Code Playgroud) 我刚刚了解到将泛型参数作为out参数类型会强制该泛型类型保持不变。这让我很惊讶。我认为out参数被视为与返回类型相同(即如果泛型参数是协变的,那么它可以用作out输出参数),因为它们都是方法的“输出”。
经过一番调查,我意识到你不能这样做:
public class Program {
public static void Main() {
// cannot convert from 'out object' to 'out string'
F(out object s); // passing an out object
}
public static void F(out string o) {
o = null;
}
}
Run Code Online (Sandbox Code Playgroud)
这解释了为什么out参数必须是不变的。但是,我仍然不明白为什么你不能这样做。众所周知,out参数只是返回值的另一种方式。F可以用返回值重写,它会起作用:
// This is the semantically equivalent version of the above, just without "out"
public class Program {
public static void Main() {
object s = F(); …Run Code Online (Sandbox Code Playgroud) 刚刚注意到这不起作用:
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) 我正在尝试将此C#方法转换为PHP.第二个参数中的out是什么意思?
public static bool Foo(string name, out string key)
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仅允许顺序返回。
我是阿达的新手.
我看到了这个问题,但我的情况有点不同:
type A is record
x : integer;
y : integer;
end record;
procedure P1 is
temp : A;
begin
temp.x := 100;
P2(temp);
if temp.x = 100 then
Ada.Text_IO.Put_Line("true");
else
Ada.Text_IO.Put_Line("false");
end if;
end One;
procedure P2 (arg1 : out A) is
begin
arg1.y := 200;
end P2;
Run Code Online (Sandbox Code Playgroud)
我的问题是P2中的"out"参数:如果P2没有明确设置它们,复合类型的其他部分将是未定义的.换句话说,如果调用P1,输出肯定是真还是假?或者可能含糊不清?
这个链接谈到"默认初始化",但我上面的例子没有明确地(有意).
Safety is preserved by ensuring that a subcomponent does not become
"deinitialized" by being passed as an out parameter. If any subcomponent
of a …Run Code Online (Sandbox Code Playgroud) 我采用了棱角分明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)