Tag: C#的

为什么有那么多的std :: swap的特化?

在查看std::swap的文档时,我看到了很多专业化的东西。 它看起来像每个STL容器,以及许多其他标准设施有一个专门的交换。 我想借助模板,我们不需要所有这些专业化? 例如, 如果我写我自己的pair它与模板版本正常工作: template<class T1,class T2> struct my_pair{ T1 t1; T2 t2; }; int main() { my_pair<int,char> x{1,'a'}; my_pair<int,char> y{2,'b'}; std::swap(x,y); } 那么从专门的std::pair获得什么呢? template< class T1, class T2 > void swap( pair<T1,T2>& lhs, pair<T1,T2>& rhs ); 我还想知道是否应该为自定义类写作自己的专业化, 或者仅仅依靠模板版本。

C#4.0:我可以使用一个颜色作为一个可选参数与默认值?

public void log(String msg, Color c = Color.black) { loggerText.ForeColor = c; loggerText.AppendText("\n" + msg); } 这会导致错误c必须是编译时常量。 我已经阅读了这一点,大多数的例子是处理string和整数。 我已经想通了,我可以使用colorconverter类,但我不知道这将是非常有效的。 有没有办法只传递一个基本的颜色作为一个可选的参数? public void log(String msg, String c = "Black") { ColorConverter conv = new ColorConverter(); Color color = (Color)conv.ConvertFromString(c); loggerText.ForeColor = color; loggerText.AppendText("\n" + msg); }

在C中是无效的数据types?

在C编程语言中是void的数据types? 如果是这样,它可以存储什么types的值? 如果我们有int , float , char等来存储值,为什么需要void ?

为什么/何时使用`intptr_t`在C中进行types转换?

我有一个关于使用intptr_t与long int 。 我发现增加内存地址(例如通过手动指针算术)因数据types而异。 例如增加一个字符指针增加1的内存地址,而增加一个int指针增加4,8为双,16为长双等… 起初,我做了这样的事情: char myChar, *pChar; float myFloat, *pFloat; pChar = &myChar; pFloat = &myFloat; printf( "pChar: %d\n", ( int )pChar ); printf( "pFloat: %d\n", ( int )pFloat ); pChar++; pFloat++; printf( "and then after incrementing,:\n\n" ); printf( "pChar: %d\n", (int)pChar ); printf( "pFloat: %d\n", (int)pFloat ); 它编译和执行得很好,但XCode给我警告我的types转换:“从指针转换为不同大小的整数”。 经过一些谷歌search和结果(后者是一个字吗?),我看到一些人推荐使用intptr_t : #include <stdint.h> […]

在debugging中禁用应用程序见解

如何在使用debuggingconfiguration时自动禁用应用程序见解并仅在发布时启用它? 有没有可能做到这一点,而不只是为了debugging创build另一个仪器钥匙? 我将trackevent的代码散布在整个代码中,将它们包含在debugging预处理程序中不是一个理想的解决scheme。 我目前的解决scheme是将ApplicationInsights.config文件的Build Action设置为None以便它不复制到项目的输出目录,但这不是一个可以基于活动生成configuration自动执行的过程。 有一个开发人员模式,但需要手动更改(如果可以有条件地设置configuration文件,清空instrumentationkey解决问题以及)。 请参阅http://apmtips.com/blog/2015/02/02/developer-mode/ 参考: http : //blogs.msdn.com/b/visualstudioalm/archive/2015/01/07/application-insights-support-for-multiple-environments-stamps-and-app-versions.aspx

在C ++中使用接口的性能损失?

在C ++中使用接口(抽象基类)时会有运行时性能损失吗?

C#:监视器 – 等待,脉冲,PulseAll

我很难理解Wait() , Pulse() , PulseAll() 。 他们都会避免死锁吗? 如果你解释如何使用它们,我将不胜感激?

'委托'System.Action'不需要0个参数。' 这是一个C#编译器错误(lambdas +两个项目)?

考虑下面的代码。 看起来像完全有效的C#代码吧? //Project B using System; public delegate void ActionSurrogate(Action addEvent); //public delegate void ActionSurrogate2(); // Using ActionSurrogate2 instead of System.Action results in the same error // Using a dummy parameter (Action<double, int>) results in the same error // Project A public static class Class1 { public static void ThisWontCompile() { ActionSurrogate b = (a) […]

用C ++创build一个简单的configuration文件和parsing器

我正在尝试创build一个看起来像这样的简单configuration文件 url = http://mysite.com file = main.exe true = 0 当程序运行时,我希望将configuration设置加载到下面列出的程序variables中。 string url, file; bool true_false; 我已经做了一些研究, 这个链接似乎有帮助(核子的post),但我似乎无法得到它的工作,这是我的一部分太复杂了。 有没有一个简单的方法来做到这一点? 我可以使用ifstream加载文件,但是尽可能的我自己。 谢谢!

只将唯一项目添加到列表

我正在通过networking宣布自己的远程设备列表。 如果以前没有添加过,我只想将设备添加到列表中。 这些公告即将通过asynchronous套接字侦听器,因此添加设备的代码可以在多个线程上运行。 我不知道我在做什么错,但没有任何我尝试我最终重复。 这是我目前拥有的….. lock (_remoteDevicesLock) { RemoteDevice rDevice = (from d in _remoteDevices where d.UUID.Trim().Equals(notifyMessage.UUID.Trim(), StringComparison.OrdinalIgnoreCase) select d).FirstOrDefault(); if (rDevice != null) { //Update Device….. } else { //Create A New Remote Device rDevice = new RemoteDevice(notifyMessage.UUID); _remoteDevices.Add(rDevice); } }