Tag: C#的

我可以调用“字节数”设置为零的memcpy()和memmove()吗?

当我实际上没有任何东西移动/复制memmove() / memcpy()作为边缘情况下,我需要处理案件吗? int numberOfBytes = … if( numberOfBytes != 0 ) { memmove( dest, source, numberOfBytes ); } 或者我应该只是调用函数而不检查 int numberOfBytes = … memmove( dest, source, numberOfBytes ); 前面的代码段中的检查是否必要?

为什么没有Convert.toFloat()方法?

为什么不存在方法Convert.ToFloat() ,C#有ToDouble() , ToDecimal() … 我想转换为浮动,可以使用哪种方法? (浮动)VAR?

更新OSX命令行工具6.3后缺lessC ++头<__ debug>

从App Store更新到命令行工具6.3后,内部包含<__ debug>的<vector>或<iterator>程序将导致文件未find错误,如下所示。 该cpp没有什么有趣的,但包括在其中一个包含的标题。 c++ -O3 -I/Users/farleylai/Documents/dev/git/ESMS/Optimizer/../StreamIt/src/cluster/headers -L/Users/farleylai/Documents/dev/git/ESMS/Optimizer/../StreamIt/build/binaries/clusterStaticLibrary /Users/farleylai/Documents/dev/git/ESMS/Optimizer/build/StreamIt/FIR/511/512/combined_threads.cpp -o streamit -lcluster -lpthread -lstdc++ In file included from /Users/farleylai/Documents/dev/git/ESMS/Optimizer/build/StreamIt/FIR/511/512/combined_threads.cpp:9: In file included from /Users/farleylai/Documents/dev/git/ESMS/Optimizer/../StreamIt/src/cluster/headers/node_server.h:22: In file included from /Users/farleylai/Documents/dev/git/ESMS/Optimizer/../StreamIt/src/cluster/headers/thread_info.h:20: In file included from /Users/farleylai/Documents/dev/git/ESMS/Optimizer/../StreamIt/src/cluster/headers/connection_info.h:19: /Users/farleylai/Documents/dev/git/ESMS/Optimizer/../StreamIt/src/cluster/headers/socket_holder.h:43:25: warning: delete called on 'mysocket' that is abstract but has non-virtual destructor [-Wdelete-non-virtual-dtor] if (!is_mem_socket) delete sock; ^ In file […]

为什么当float不能表示所有的int值时,C ++将int提升为float?

说我有以下几点: int i = 23; float f = 3.14; if (i == f) // do something i将被提升为一个float ,并将两个float进行比较,但float是否可以表示所有的int值? 为什么不把int和float提升为double ?

将一个const引用返回给一个对象,而不是一个副本

在重构一些代码的同时,我遇到了一些返回std :: string的getter方法。 像这样的东西,例如: class foo { private: std::string name_; public: std::string name() { return name_; } }; 当然,getter会更好的返回一个const std::string& ? 目前的方法是返回一个效率不高的副本。 会返回一个const引用,而不是导致任何问题?

HttpClient.GetAsync与networking凭据

我目前正在使用HttpWebRequest来获得一个网站。 我想使用await模式,这是不给HttpWebRequests 。 我发现类HttpClient ,这似乎是新的Http工人类。 我使用HttpClient.GetAsync(…)来查询我的网页。 但我错过了像HttpWebRequest.Credentials一样添加ClientCredientials的选项。 有什么办法给HttpClient身份validation信息?

挣扎试图让Cookie不符合.net 4.5中的HttpClient的响应

我有下面的代码,成功的工作。 我无法弄清楚如何从响应中获取cookie。 我的目标是,我希望能够在请求中设置cookie,并将cookie从响应中取出。 思考? private async Task<string> Login(string username, string password) { try { string url = "http://app.agelessemail.com/account/login/"; Uri address = new Uri(url); var postData = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("username", username), new KeyValuePair<string, string>("password ", password) }; HttpContent content = new FormUrlEncodedContent(postData); var cookieJar = new CookieContainer(); var handler = new HttpClientHandler […]

德摩根定律与重载操作符的优化

每个程序员都应该知道: ( 德摩根定律) 在某些情况下,为了优化程序,可能会发生编译器将(!p && !q)修改为(!(p || q)) 。 这两个expression式是等价的,对第一个和第二个expression式没有任何区别。 但是在C ++中,可能会重载操作符,重载操作符可能并不总是尊重这个属性。 所以这样转换代码实际上会修改代码。 如果编译器使用De Morgan's Laws ! , || 和&&超载?

你调用的对象是空的。

当我运行程序时,我一直收到这个错误。 你调用的对象是空的。 说明:执行当前Web请求期间发生未处理的exception。 请查看堆栈跟踪,了解有关错误的更多信息以及源代码的位置。 exception详细信息:System.NullReferenceException:未将对象引用设置为对象的实例。 Source Error: Line with error: Line 156: if (strSearch == "" || strSearch.Trim().Length == 0) 它应该写的正确方法是什么?

在成员函数内的lambda捕获列表中使用成员variables

以下代码使用gcc 4.5.1进行编译,但不使用VS2010 SP1进行编译: #include <iostream> #include <vector> #include <map> #include <utility> #include <set> #include <algorithm> using namespace std; class puzzle { vector<vector<int>> grid; map<int,set<int>> groups; public: int member_function(); }; int puzzle::member_function() { int i; for_each(groups.cbegin(),groups.cend(),[grid,&i](pair<int,set<int>> group){ i++; cout<<i<<endl; }); } int main() { return 0; } 这是错误的: error C3480: 'puzzle::grid': a lambda capture variable must […]