Tag: C#的

如何读取特定文件夹内的所有文件

我想读取c#.net中特定文件夹内的所有xml文件 XDocument doc2 = XDocument.Load((PG.SMNR.XMLDataSourceUtil.GetXMLFilePath(Locale, "Products/category/product.xml"))); 我有多个产品在类别文件夹..要循环的文件夹,并应获得所有产品的XML文件名。 XDocument doc2 = XDocument.Load((PG.SMNR.XMLDataSourceUtil.GetXMLFilePath(Locale, "Products/category/x1.xml")));

什么是在C#lambdavariables的范围?

我对lambdavariables的范围感到困惑,比如下面的例子 var query = from customer in clist from order in olist .Where(o => o.CustomerID == customer.CustomerID && o.OrderDate == // line 1 olist.Where(o1 => o1.CustomerID == customer.CustomerID) // line 2 .Max(o1 => o1.OrderDate) // line 3 ) select new { customer.CustomerID, customer.Name, customer.Address, order.Product, order.OrderDate }; 在第一行中,我已经声明了一个lambdavariables“o”,这意味着我不能在第二行再次声明它(或者至less编译器会抱怨,如果我尝试的话)但是即使'o1'已经存在,它也不会抱怨第3行?? 什么是lambdavariables的范围?

计算机存储器中存储的“this”指针在哪里?

“this”指针在哪里存储在内存中? 它是分配在堆栈中,堆中还是数据段中? #include <iostream> using namespace std; class ClassA { int a, b; public: void add() { a = 10; b = 20; cout << a << b << endl; } }; int main() { ClassA obj; obj.add(); return 0; } 在上面的代码中,我调用成员函数add() ,接收者对象作为“this”指针隐式传递。 这里存储在内存中?

包含反斜杠的pathstring无法识别的转义序列

以下代码为每个反斜杠生成一个有关“无法识别的转义序列”的编译器错误: string foo = "D:\Projects\Some\Kind\Of\Pathproblem\wuhoo.xml"; 我想我需要逃避反斜杠? 我怎么做?

我如何获得本地机器名称?

我如何获得本地机器名称?

testing一个对象是一个枚举

我想知道'theObject'是一个枚举(任何枚举types) foreach (var item in Enum.GetValues(theObject.GetType())) { //do something }

find最内层的exception,而不使用while循环?

当C#抛出一个exception时,它可能会有一个内部exception。 我想要做的是得到最内在的exception,换句话说,没有内部exception的叶子exception。 我可以在一个while循环中做到这一点: while (e.InnerException != null) { e = e.InnerException; } 但是我想知道是否有一些我可以用来做这个的。

为什么“noreturn”函数返回?

我读了关于noreturn属性的这个问题,它用于不返回给调用者的函数。 然后我用C做了一个程序 #include <stdio.h> #include <stdnoreturn.h> noreturn void func() { printf("noreturn func\n"); } int main() { func(); } 并使用此代码生成组装: .LC0: .string "func" func: pushq %rbp movq %rsp, %rbp movl $.LC0, %edi call puts nop popq %rbp ret // ==> Here function return value. main: pushq %rbp movq %rsp, %rbp movl $0, %eax call func 为什么函数func()在提供noreturn属性后返回?

有没有办法使string文件path在C#安全?

我的程序将从互联网上采取任意string,并将其用于文件名。 有一个简单的方法来从这些string中删除错误的字符,或者我需要为此编写一个自定义函数吗?

在C ++中进行函数式编程。 实施f(a)(b)(c)

我一直在使用C ++进行函数式编程的基础知识。 我试图做一个函数f(a)(b)(c) ,将返回a + b + c 。 我成功实现了函数f(a)(b) ,它返回a + b。 这是它的代码: std::function<double(double)> plus2(double a){ return[a](double b){return a + b; }; } 我只是不知道如何实现函数f(a)(b)(c) ,正如我以前所说,应该返回a + b + c 。