Tag: C#的

在编程中(数字和数字)是什么意思?

例如: int get(int i) { int res = 0; while (i) { res = (res + tree[i]) % MOD; i -= ( (i) & (-i) ); } return res; } 树更新function: void update(int i, int val) { while (i <= m) { tree[i] = (tree[i] + val) % MOD; i += ( (i) & (-i) […]

Web.Configdebugging/发布

我知道在Visual Studio 2010中的web.config提供了从数据库从debugging模式切换到发布模式的能力。 这是我的Web.Release.config: <?xml version="1.0"?> <!– For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 –> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <connectionStrings> <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" /> <add name="Testing1" connectionString="Data Source=test;Initial Catalog=TestDatabase;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings> <system.web> <compilation xdt:Transform="RemoveAttributes(debug)" /> </system.web> </configuration> 这是我的Web.Debug.config代码: <?xml version="1.0"?> <!– For more information on using web.config transformation visit […]

我应该返回std ::string?

我试图尽可能使用std::string而不是char* ,但是我担心可能会降低性能。 这是一个返回string的好方法(为简洁起见没有错误检查)? std::string linux_settings_provider::get_home_folder() { return std::string(getenv("HOME")); } 此外,一个相关的问题:当接受string作为参数,我应该收到他们作为const std::string&或const char* ? 谢谢。

重用内存位置安全吗?

这个问题是基于一些现有的C代码移植到C ++。 我只是对它是否“安全”感兴趣。 我已经知道我不会这样写了。 我知道这里的代码基本上是C而不是C ++,但它是用C ++编译器编译的,而且我知道这些标准有时会略有不同。 我有一个分配一些内存的函数。 我将返回的void*转换为int*并开始使用它。 后来我将返回的void*转换为Data*并开始使用它。 这在C ++中是安全的吗? 例如: – void* data = malloc(10000); int* data_i = (int*)data; *data_i = 123; printf("%d\n", *data_i); Data* data_d = (Data*)data; data_d->value = 456; printf("%d\n", data_d->value); 我从不读取通过与存储types不同的types使用的variables,但担心编译器可能会看到data_i和data_d是不同的types,因此不能合法地互相data_i ,并决定重新sorting我的代码,例如将商店放到data_d第一个printf 。 哪个会打破一切。 然而,这是一直在使用的模式。 如果在两次访问之间插入一个free和malloc ,我不相信它会改变任何事情,因为它不会触及受影响的内存本身,并可以重复使用相同的数据。 我的代码是否被破坏或“正确”?

.NET中“HttpRequest.RequestType”和“WebRequest.Method”值的常量在哪里?

我需要检查ASP.NET(或WebRequest.Method )中的HttpRequest的RequestType 。 我知道我可以使用string值“ POST ”或“ GET ”作为请求types,但是我可以发誓在.NET中的某个类中包含了这些值。 出于好奇,我想知道是否有人知道这些string常量的GET和POST是什么类。我试过在线search,但我没有运气,所以我想我会问这里。

使C浮点文字浮动(而不是双)

众所周知,在C中,浮点文字(例如1.23 )具有doubletypes。 因此,任何涉及他们的计算都会提升一倍。 我正在开发一个embedded式实时系统,它有一个浮点单元,它只支持单精度float 。 我所有的variables都是float ,这个精度就足够了。 我根本不需要(也买不起)。 但每次都是这样 if (x < 2.5) … 写道,灾难发生:减速可能高达两个数量级。 当然,直接的答案是写 if (x < 2.5f) … 但这很容易错过(而且很难检测,直到太晚),特别是当一个“configuration”值被一个不太严格的(或者是新的)开发者在一个单独的文件中定义的时候。 那么,是否有办法强制编译器将所有(浮点)文字视为float,就像后缀f ? 即使违反规范,我也不在乎。 还是其他解决scheme? 顺便说一句,编译器是gcc。

使用Boost库程序选项的必需和可选参数

我正在使用Boost程序选项库来parsing命令行参数。 我有以下要求: 一旦提供“帮助”,所有其他选项都是可选的; 一旦“帮助”没有提供,所有其他选项是必需的。 我如何处理这个? 这是我的代码处理这个,我发现它是非常多余的,我认为必须有一个容易做的,对吧? #include <boost/program_options.hpp> #include <iostream> #include <sstream> namespace po = boost::program_options; bool process_command_line(int argc, char** argv, std::string& host, std::string& port, std::string& configDir) { int iport; try { po::options_description desc("Program Usage", 1024, 512); desc.add_options() ("help", "produce help message") ("host,h", po::value<std::string>(&host), "set the host server") ("port,p", po::value<int>(&iport), "set the server port") ("config,c", […]

GDB:如果variables相等,则中断

我想让GDB设置一个断点,当一个variables等于我设置的某个值时,我试过这个例子: #include <stdio.h> main() { int i = 0; for(i=0;i<7;++i) printf("%d\n", i); return 0; } GDB输出: (gdb) break if ((int)i == 5) No default breakpoint address now. (gdb) run Starting program: /home/SIFE/run 0 1 2 3 4 5 6 Program exited normally. (gdb) 就像你看到的那样,GDB没有任何突破点,这对GDB来说可能吗?

Visual Studio 2010的全局源代码控制应该包含哪些内容?

在安装和使用Visual Studio 2010之后,我看到一些较新的文件types(至less在C ++项目中…不知道其他types)与2008相比。例如.sdf,.opensdf,我猜使用存储在SQL Server Compact文件中的Intellisense信息replacencb文件? 我也注意到.log文件生成,似乎是生成日志。 鉴于此,有什么安全添加到我的全局忽略模式? 蝙蝠,我会假设.sdf,.opensdf,但还有什么?

检查给定的完整path

有没有一种方法来检查给定的path是否是完整path? 现在我要做这个: if (template.Contains(":\\")) //full path already given { } else //calculate the path from local assembly { } 但是一定要有更优雅的方式来检查这个吗?