Tag: C#的

为什么sizeof(无符号双)等于4?

我的一个同事问是否有无符号的双倍,我说没有,但我仍然检查它,这在Microsoft Visual C ++ 2010编译: unsigned double a; double b; printf("size_a=%d size_b=%d", (int) sizeof(a), (int) sizeof(b)); 它输出size_a=4 size_b=8 。 也就是说, unsigned double双字节是四个字节,双字节是八个字节。

Todo任务不会出现在Visual Studio 2012中的任务列表中

我最近升级到Visual Studio 2012,没有任何问题,除了以“// todo”开头的注释不再出现在任务列表中。 我完全不知道从哪里开始寻找这个问题的解决scheme,因为所有的关键字太笼统了。 我遇到了其他类似的问题,答案是该文件未公开包含//待办事项评论,但对我来说并不是这样。 即使文件在我面前打开,我的待办事项评论也不会显示出来。

在Linq中,仅基于表的一个字段

我正在尝试在Linq中使用.distinct来获得基于表的一个字段的结果(所以不需要从表中整个重复的logging)。 我知道使用不同的基本查询,如下所示: var query = (from r in table1 orderby r.Text select r).distinct(); 但是我需要r.text不重复的结果。

在ToString()之前检查null

这是场景… if (entry.Properties["something"].Value != null) attribs.something = entry.Properties["something"].Value.ToString(); 虽然有效和正确工作,这对我来说看起来很丑。 如果在执行ToString()之前不检查null,那么如果属性为null,则会引发exception。 有没有更好的方法来处理这种情况? 非常感激!

Double.TryParse或Convert.ToDouble – 哪个更快更安全?

我的应用程序使用VSTO读取Excel文件,并将读取的数据添加到StringDictionary 。 它只添加数字,只有几位数字(1000 1000,2 1000,34 – 逗号是俄罗斯标准中的分隔符)。 有什么更好的检查,如果当前string是一个合适的数字? object data, string key; // data had read try { Convert.ToDouble(regionData, CultureInfo.CurrentCulture); dic.Add(key, regionData.ToString()); } catch (InvalidCastException) { // is not a number } 要么 double d; string str = data.ToString(); if (Double.TryParse(str, out d)) // if done, then is a number { dic.Add(key, str); } 我必须使用StringDictionary而不是Dictionary<string, […]

libstdc ++。so.6:无法打开共享目标文件:没有这样的文件或目录

我想用cilk ++程序运行Cilkscreen命令,但是我得到了这个错误 /usr/local/cilk/bin/../lib32/pinbin加载共享库时出错:libstdc ++。so.6:无法打开共享目标文件:没有这样的文件或目录 你能帮我吗

variables的声明是昂贵的吗?

在C编码时,我遇到了下面的情况。 int function () { if (!somecondition) return false; internalStructure *str1; internalStructure *str2; char *dataPointer; float xyz; /* do something here with the above local variables */ } 考虑到上面的代码中的if语句可以从函数返回,我可以在两个地方声明variables。 在if语句之前。 在if语句之后。 作为一名程序员,我想在if语句之后保留variables声明。 申报地点是否有成本? 还是有其他的理由比其他的更喜欢一种方式?

ConcurrentDictionary AddOrUpdate

我正在尝试使用Dictionary重新编写一些代码来使用ConcurrentDictionary。 我已经回顾了一些例子,但是我仍然无法实现AddOrUpdate函数。 这是原始的代码: dynamic a = HttpContext; Dictionary<int, string> userDic = this.HttpContext.Application["UserSessionList"] as Dictionary<int, String>; if (userDic != null) { if (useDic.ContainsKey(authUser.UserId)) { userDic.Remove(authUser.UserId); } } else { userDic = new Dictionary<int,string>(); } userDic.Add(authUser.UserId, a.Session.SessionID.ToString()); this.HttpContext.Application["UserDic"] = userDic; 我不知道要为更新部分添加什么: userDic.AddOrUpdate(authUser.UserId, a.Session.SessionID.ToString(), /*** what to add here? ***/); 任何指针将不胜感激。

如何在ASP.NET Core中设置Automapper

我在.NET方面比较新,而且我决定解决.NET Core问题,而不是学习“老方法”。 我在这里find了一个关于设置AutoMapper for .NET Core的详细文章,但是对于新手来说,有没有更简单的漫游?

你最喜欢的LINQ to Objects运算符是不是内置的?

使用扩展方法,我们可以编写方便的LINQ操作符来解决一般问题。 我想知道在System.Linq命名空间中缺less哪些方法或重载以及如何实现它们。 清洁和优雅的实现,可能使用现有的方法,是首选。