考虑以下代码:
public class Program
{
private static void Main(string[] args)
{
var person1 = new Person { Name = "Test" };
Console.WriteLine(person1.Name);
Person person2 = person1;
person2.Name = "Shahrooz";
Console.WriteLine(person1.Name); //Output: Shahrooz
person2 = null;
Console.WriteLine(person1.Name); //Output: Shahrooz
}
}
public class Person
{
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
很显然,当分配person1
到person2
与Name
物业person2
发生变化,Name
中person1
也将改变.person1
并person2
有相同的参考.
为什么何时person2 = null
,person1
变量也不会为空?
我想填充一个vector<int>
使用std::fill
,但不是一个值,矢量应该包含数字后增加的顺序.
我尝试通过迭代函数的第三个参数来实现这一点,但这只会给我一个填充1或2的向量(取决于++
运算符的位置).
例:
vector<int> ivec;
int i = 0;
std::fill(ivec.begin(), ivec.end(), i++); // elements are set to 1
std::fill(ivec.begin(), ivec.end(), ++i); // elements are set to 2
Run Code Online (Sandbox Code Playgroud) 我在C#工作,我的工作场所有一些代码标准.其中之一是我们连接的每个事件处理程序(例如KeyDown
)必须在Dispose
方法中断开连接.这有什么好的理由吗?
我有一个Question对象列表,我用a ForEach
来遍历列表.对于每个对象,我都会将.Add
其添加到我的实体框架中,然后添加到数据库中.
List<Question> add = problem.Questions.ToList();
add.ForEach(_obj => _uow.Questions.Add(_obj));
Run Code Online (Sandbox Code Playgroud)
我需要修改其中的每个对象ForEach
并将AssignedDate
字段设置 为DateTime.Now
.有没有办法在ForEach
循环中做到这一点?
我试图使用一组对象
(array = [{name: 'Moe', id:1}, {name: 'Larry', id:2}, {name: 'Curly', id:3}])
Run Code Online (Sandbox Code Playgroud)
作为AngularJS输入表单中的下拉选择,我需要一个例子.任何人都可以指向一个可以启发我的jsFiddle吗?
myarray.indexOf(element)
即使元素出现在myarray中,我也会得到-1 .
这是一些代码片段:
function createChangeRecord( old_array, new_array ) {
var nds = new_array.slice(0,new_array.length);
var el, idx;
if (...) {
...
} else if ( old_array.length==new_array.length ) {
for ( var i=0; i<old_array.length; i++ ) {
el = old_array[i];
idx = nds.indexOf(el);
if ( idx!=(-1) ) {
...
} else {
var a = "el: " + el + "; nds: " + nds + "; nds.indexOf(el): " + nds.indexOf(el);
alert( a );
...
}
}
...
}
...
} …
Run Code Online (Sandbox Code Playgroud) 我在程序集中有这个代码:
public class Class1
{
public const int x = 10;
}
Run Code Online (Sandbox Code Playgroud)
在我有一个不同的集会:
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Class1.x);
Console.ReadKey();
}
}
Run Code Online (Sandbox Code Playgroud)
当然,产量10
,但后来我改x
到20
:
public class Class1
{
public const int x = 20;
}
Run Code Online (Sandbox Code Playgroud)
我重新编译了程序集并将其移动到我的命令行程序的bin目录中.但是,我的程序输出仍然是10
,直到我编译包含该main
函数的程序集.
为什么会这样?
我正在尝试理解C#Volatile类.
正如我读到的:
该Volatile.Write
方法强制将位置中的值写入调用点.此外,任何早期的程序订单加载和存储必须在调用Volatile.Write之前发生.
该Volatile.Read
方法强制在呼叫点读取位置中的值.此外,任何后续的程序订单加载和存储必须在调用Volatile.Read之后发生.
这是否意味着:
internal sealed class ThreadsSharingData {
private Int32 m_flag = 0;
private Int32 m_value = 0;
// This method is executed by one thread
public void Thread1() {
// Note: 5 must be written to m_value before 1 is written to m_flag
m_value = 5;
Volatile.Write(ref m_flag, 1);
}
// This method is executed by another thread
public void Thread2() {
// Note: m_value must be read after m_flag is read
if …
Run Code Online (Sandbox Code Playgroud) TParallel.For()
有一个称为的论点AStride
.在我的情况下,AStride是2:
TParallel.&For(2, 1, 10,
procedure(index: Integer)
begin
TThread.Queue(nil,
procedure
begin
memo1.Lines.Add(index.ToString());
end
);
end
);
Run Code Online (Sandbox Code Playgroud)
我在这里无法理解"AStride"的技术含义.是否AStride = 2
意味着第一个线程将处理该范围内的两个连续数字[1..10]
,第二个线程将处理下一个连续数字等?
**英语不是我的母语,我将"Stride"翻译为"long step"或"pace".
我想在kibana 4"Discover"页面中通过查询运行一个简单的sql组.我的弹性搜索索引中的每条记录代表一个日志并有3列:process_id (not unique value), log_time, log_message
.
例:
process_id log_time log_message
---------------- -------------------- -------------- ------
1 2014/12/11 01:00 msg1
1 2014/12/11 01:10 msg2
1 2014/12/11 01:20 msg3
2 2014/12/11 11:00 msg4
2 2014/12/11 11:10 msg5
我想在kibana中生成一个表格,如下所示:
process_id first log_time last log_time
---------------- ------------------------ ---------- ----------
1 2014/12/11 01:00 2014/12/11 01:20
2 2014/12/11 11:00 2014/12/11 11:10
在sql中,查询很简单:通过process_id从logs_table group中选择process_id,max(log_time),min(log_time)
如何在Kibana中运行此查询?是否可以在"发现"页面中运行查询,还是应该创建一个面板(可视化页面)?
谢谢.