Tag: C#的

如何在C中打印“unsigned long”?

我永远不能理解如何在C中打印unsigned long数据types 假设unsigned_foo是一个unsigned long ,那么我试试: printf("%lu\n", unsigned_foo) printf("%du\n", unsigned_foo) printf("%ud\n", unsigned_foo) printf("%ll\n", unsigned_foo) printf("%ld\n", unsigned_foo) printf("%dl\n", unsigned_foo) 而他们都打印某种-123123123号码,而不是unsigned long ,我有。

初始化对象时{0}是什么意思?

当{0}被用来初始化一个对象时,它是什么意思? 我无法在任何地方find任何对{0}引用,并且由于Google大括号的search没有帮助。 示例代码: SHELLEXECUTEINFO sexi = {0}; // what does this do? sexi.cbSize = sizeof(SHELLEXECUTEINFO); sexi.hwnd = NULL; sexi.fMask = SEE_MASK_NOCLOSEPROCESS; sexi.lpFile = lpFile.c_str(); sexi.lpParameters = args; sexi.nShow = nShow; if(ShellExecuteEx(&sexi)) { DWORD wait = WaitForSingleObject(sexi.hProcess, INFINITE); if(wait == WAIT_OBJECT_0) GetExitCodeProcess(sexi.hProcess, &returnCode); } 没有它,上面的代码将在运行时崩溃。

正确的方法来初始化一个C#字典的值已经在它?

我正在用下面的代码在C#文件中创build一个字典: private readonly Dictionary<string, XlFileFormat> FILE_TYPE_DICT = new Dictionary<string, XlFileFormat> { {"csv", XlFileFormat.xlCSV}, {"html", XlFileFormat.xlHtml} }; 在new的下面有一个红线,错误: function“集合初始化程序”不能被使用,因为它不是ISO-2 C#语言规范的一部分 任何人都可以解释这里发生了什么? 编辑:好的,所以事实certificate,我使用.NET版本2。

为什么我的程序不能在Windows 7下用法语编译?

我正在运行Windows 7法语,我试图编译这个非常基本的程序,但Visual Studio正在固执地拒绝遵守。 我也尝试在Coliru上使用GCC 4.7和Clang trunk来编译它,并且我得到或多或less相同的错误(输出在代码之下),但是我认为Coliru运行在英文操作系统上,所以我不希望它能够正常工作。 我究竟做错了什么? 我该如何解决? 码 #inclure <iostream> ent principal(ent argn, ent** argm) // entier, nombre d'arguments, valeur des arguments { std::cendehors << "Bonjour le monde!\n"; renvoi SORTIE_SUCCÈS; } 产量 principal.cpp:1:6: erreur: prétraitement de la directive invalide #inclure #inclure <iostream> ^ principal.cpp:6:8: erreur: '\303' égaré dans le programme renvoi SORTIE_SUCCÈS; ^ principal.cpp:6:8: […]

用g ++编译C ++ 11

我正在尝试将我的C ++编译器更新到C ++ 11。 我已经search了一下,我得出结论,我必须使用标志-std=c++0x或-std=gnu++0x ,但我不知道关于标志的许多事情。 谁能帮我? (我正在使用Ubuntu 12.04。) 这里是我从编译器中得到的错误,当我尝试使用包含在C ++ 11(即数组)中的库时: #include <array> #include <iostream> int main() { std::array<int, 3> arr = {2, 3, 5}; … } This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or […]

任何人都可以解释这个奇怪的行为,在C#签署花车?

这里有一个评论的例子: class Program { // first version of structure public struct D1 { public double d; public int f; } // during some changes in code then we got D2 from D1 // Field f type became double while it was int before public struct D2 { public double d; public double f; } static […]

为什么这个循环在某些平台上退出,而不是在其他平台上退出?

我最近开始学习C,我正在以C为主题的课。 我目前正在玩循环,我遇到了一些奇怪的行为,我不知道如何解释。 #include <stdio.h> int main() { int array[10],i; for (i = 0; i <=10 ; i++) { array[i]=0; /*code should never terminate*/ printf("test \n"); } printf("%d \n", sizeof(array)/sizeof(int)); return 0; } 在我的笔记本电脑上运行Ubuntu 14.04,这个代码不会中断。 它运行完成。 在我学校的电脑上运行CentOS 6.6,它也运行良好。 在Windows 8.1上,循环永远不会终止。 更奇怪的是,当我将for循环的条件编辑为: i <= 11 ,代码仅在运行Ubuntu的笔记本电脑上终止。 它永远不会终止在CentOS和Windows。 任何人都可以解释内存中发生了什么,以及为什么不同的操作系统运行相同的代码会产生不同的结果? 编辑:我知道for循环超出界限。 我正在故意的 我只是无法弄清楚在不同的操作系统和计算机上,行为是如何不同的。

在结构上使用“新”是否将它分配到堆或栈上?

当用new运算符创build一个类的实例时,内存将被分配到堆上。 当你用new运算符创build一个结构体的实例时,内存被分配到哪里,在堆上还是在栈上?

在C#中的typedef等效

在C#中是否有一个typedef等价物,或者有些类似的行为? 我做了一些谷歌search,但我看起来似乎是负面的。 目前我有一个类似于以下的情况: class GenericClass<T> { public event EventHandler<EventData> MyEvent; public class EventData : EventArgs { /* snip */ } // … snip } 现在,火箭科学家并没有弄清楚,当试图为这个事件实现一个处理程序时,这很快就会导致大量的input(为可怕的双关语表示歉意)。 它最终会是这样的: GenericClass<int> gcInt = new GenericClass<int>; gcInt.MyEvent += new EventHandler<GenericClass<int>.EventData>(gcInt_MyEvent); // … private void gcInt_MyEvent(object sender, GenericClass<int>.EventData e) { throw new NotImplementedException(); } 除了我的情况,我已经在使用一个复杂的types,而不仅仅是一个int。 如果有可能简化这一点就好了… 编辑:即。 也许是敲入EventHandler而不需要重新定义它来获得类似的行为。

为什么是0 <-0x80000000?

我有一个简单的程序下面: #include <stdio.h> #define INT32_MIN (-0x80000000) int main(void) { long long bal = 0; if(bal < INT32_MIN ) { printf("Failed!!!"); } else { printf("Success!!!"); } return 0; } if(bal < INT32_MIN )始终为真的条件。 这怎么可能? 它工作正常,如果我改变macros: #define INT32_MIN (-2147483648L) 任何人都可以指出这个问题?