Tag: C#的

C#list.Orderby降序

我希望收到一个按 “Product.Name” sorting的列表 。 类似于下面按升序对列表进行sorting的function,正好相反,这可能吗? var newList = list.OrderBy(x => x.Product.Name).ToList();

如何在Visual Studio 2008中永久禁用区域折叠

任何人都知道如何closuresVisual Studio 2008中的代码折叠? 我的一些同事喜欢它,但我个人总是希望看到所有的代码,并且不要让代码折叠在视线之外。 我想要一个设置,这意味着我的Visual Studio副本从不折叠#regions或function主体。

在C ++中使用“typeid”与“typeof”

我想知道在C + + typeid和typeof之间有什么区别。 以下是我所知道的: 在C ++头文件typeinfo中定义的type_info文档中提到了typeid 。 typeof在C的GCC扩展和C ++ Boost库中定义。 另外,这里是我创build的testing代码testing,发现typeid不会返回我所期望的。 为什么? main.cpp中 #include <iostream> #include <typeinfo> //for 'typeid' to work class Person { public: // … Person members … virtual ~Person() {} }; class Employee : public Person { // … Employee members … }; int main () { Person person; Employee employee; […]

为什么编译器报告缺less分号?

我有这个简单的程序: #include <stdio.h> struct S { int i; }; void swap(struct S *a, struct S *b) { struct S temp; temp = *a /* Oops, missing a semicolon here… */ *a = *b; *b = temp; } int main(void) { struct S a = { 1 }; struct S b = { 2 }; swap(&a, […]

让gdb保存一个断点列表?

好的,信息中断列出了断点,但不是以一种格式来处理, 就像在这个问题中一样使用–command重用它们。 gdb是否有方法将它们转储到一个可接受的input文件中? 有时在debugging会话中,build立一组testing断点之后,有必要重新启动gdb。 编辑: .gdbinit文件与–command有相同的问题。 info break命令不会列出命令,而是一个供人类使用的表格。 详细来说,这里是一个信息中断的例子: (gdb)信息中断 Num Type Disp Enb Address什么 1断点保持y 0x08048517 <foo :: bar(void)+7>

什么和何时使用Tuple?

请有人解释一下Tuple是什么以及如何在真实世界场景中使用它。 我想知道这可以丰富我的编码体验吗?

#ifdef在C#中

我想要做的下面,但在C#而不是C ++ #ifdef _DEBUG bool bypassCheck=TRUE_OR_FALSE;//i will decide depending on what i am debugging #else bool bypassCheck = false; //NEVER bypass it #endif

在case语句中使用{}。 为什么?

在case语句中使用{和}有什么意义? 通常情况下,无论case语句中有多less行,都会执行所有的行。 这只是一个关于较旧/较新的编译器的规则还是有一些背后的东西? int a = 0; switch (a) { case 0:{ std::cout << "line1\n"; std::cout << "line2\n"; break; } } 和 int a = 0; switch (a) { case 0: std::cout << "line1\n"; std::cout << "line2\n"; break; }

我如何使一个方法的返回types是通用的?

有没有办法使这个方法通用,所以我可以返回一个string,布尔,整数,或双? 现在,它返回一个string,但如果它能find“true”或“false”作为configuration值,我想返回一个布尔例如。 public static string ConfigSetting(string settingName) { return ConfigurationManager.AppSettings[settingName]; }

为什么标志枚举通常用hex数值定义

很多时候,我看到使用hex值的标志枚举声明。 例如: [Flags] public enum MyEnum { None = 0x0, Flag1 = 0x1, Flag2 = 0x2, Flag3 = 0x4, Flag4 = 0x8, Flag5 = 0x10 } 当我声明一个枚举时,我通常会这样声明: [Flags] public enum MyEnum { None = 0, Flag1 = 1, Flag2 = 2, Flag3 = 4, Flag4 = 8, Flag5 = 16 } 为什么有些人select用hex而不是十进制来编写数值,是否有理由或理由? 我看到它的方式,使用hex值时会更容易混淆,并且不小心写入Flag5 = 0x16而不是Flag5 […]