我的一位开发人员有一个类似于以下代码段的代码
class Data
{
public string Prop1
{
get
{
// return the value stored in the database via a query
}
set
{
// Save the data to local variable
}
}
public void SaveData()
{
// Write all the properties to a file
}
}
class Program
{
public void SaveData()
{
Data d = new Data();
// Fetch the information from database and fill the local variable
d.Prop1 = d.Prop1;
d.SaveData();
}
}
Run Code Online (Sandbox Code Playgroud)
这里的Data类属性动态地从DB中获取信息.当需要将数据保存到文件时,开发人员创建实例并使用自我赋值填充属性.然后最后调用一个保存.我试图争论财产的使用是不正确的.但他并不相信.
这是他的观点
我正在阅读有关C#4.0的一些演示文稿,最后演示者使用以下代码发布了一个测验.
using System;
class Base {
public virtual void Foo(int x = 4, int y = 5) {
Console.WriteLine("B x:{0}, y:{1}", x, y);
}
}
class Derived : Base {
public override void Foo(int y = 4, int x = 5) {
Console.WriteLine("D x:{0}, y:{1}", x, y);
}
}
class Program {
static void Main(string[] args) {
Base b = new Derived();
b.Foo(y:1,x:0);
}
}
// The output is
// D x:1, y:0
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚为什么产生输出(没有演示者离线阅读演示文稿的问题).我在期待
D x:0, y:1
Run Code Online (Sandbox Code Playgroud)
我在网上搜索找到答案,但仍然无法找到答案.有人可以解释一下吗?
作为.net开发人员,有时会要求一个人在不同的机器(32和64位)上调试,而不是自己的开发者机器.很多时候缺少一些重要的工具,我必须先安装它们才能开始调试.然后我开始在1GB记忆棒中收集一些便携式工具.目前它包含
是否有任何可以添加到集合中的可移植工具,这将有助于调试.net应用程序中的问题.你的便携式收藏品是什么?
我试图理解这个问题的答案为什么我在调用Func <int>时得到错误的结果?我写了一些示例代码.以下代码
public static void Main(string[] args)
{
var funcs = new List<Func<string>>();
for(int v=0,i=0;v<3;v++,i++)
{
funcs.Add( new Func<string>(delegate(){return "Hello "+ i++ +" "+v;}) );
}
foreach(var f in funcs)
Console.WriteLine(f());
}
Run Code Online (Sandbox Code Playgroud)
产生
Hello 3 3
Hello 4 3
Hello 5 3
Run Code Online (Sandbox Code Playgroud)
在阅读了Jon Skeet和Eric Lippert的解释后,我想我会得到
Hello 3 3
Hello 3 3
Hello 3 3
Run Code Online (Sandbox Code Playgroud)
这里v和i都是循环变量,而i的值在那个瞬间被拾取v不是为什么这个?我不明白这种行为.