Tag: C#的

在哪种情况下,我使用特定的STL容器?

我一直在阅读关于C ++的STL容器,特别是关于STL及其容器的部分。 现在我明白每一个人都有自己的特定属性,而且我已经接近了记住他们所有的人……但是我还没有把握的是在哪种情况下他们都被使用了。 什么是解释? 示例代码非常喜欢。

\ d效率低于

我昨天发表了一个评论,有人用[0123456789]作为正则expression式而不是[0-9]或\d 。 我说,使用范围或数字说明符可能比字符集更有效。 我决定今天testing一下,发现令我吃惊的是(至less在C#正则expression式引擎中) \d似乎比其他两个似乎没有太大的差别。 这是我的testing输出超过10000随机string1000个随机字符与5077实际上包含一个数字: Regular expression \d took 00:00:00.2141226 result: 5077/10000 Regular expression [0-9] took 00:00:00.1357972 result: 5077/10000 63.42 % of first Regular expression [0123456789] took 00:00:00.1388997 result: 5077/10000 64.87 % of first 有两个原因令我感到惊讶: 我会认为范围将比集合更有效地执行。 我不明白为什么\d比[0-9]更糟糕。 除了简单的[0-9]之外还有更多的东西吗? 这里是testing代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.Text.RegularExpressions; namespace SO_RegexPerformance { […]

使用FtpWebRequest输出日志

我想知道是否有可能使用FtpWebRequest为我的FTP客户端输出日志。 像这样的东西: [R] USER xxx [R] 331 Please specify the password. [R] PASS (hidden) [R] 230 Login successful. [R] SYST [R] 215 UNIX Type: L8 [R] FEAT [R] 211-Features: [R] EPRT [R] EPSV [R] MDTM [R] PASV [R] REST STREAM [R] SIZE [R] TVFS [R] 211 End [R] PWD [R] 257 "/" [R] CWD / […]

C#string枚举

我有以下枚举: public enum AuthenticationMethod { FORMS = 1, WINDOWSAUTHENTICATION = 2, SINGLESIGNON = 3 } 然而,问题是当我要求AuthenticationMethod.FORMS而不是id 1时,我需要“FORMS”这个词。 我已经find了这个问题的下面的解决scheme( 链接 ): 首先,我需要创build一个名为“StringValue”的自定义属性: public class StringValue : System.Attribute { private readonly string _value; public StringValue(string value) { _value = value; } public string Value { get { return _value; } } } 然后我可以将这个属性添加到我的枚举器中: public enum AuthenticationMethod { […]

铸造诠释枚举在C#

如何将一个int为C#中的enum ?

你最喜欢的C#扩展方法是什么? (codeplex.com/extensionoverflow)

让我们列出你发布你的优秀和最喜欢的扩展方法的答案。 要求是必须发布完整的代码,以及如何使用它的例子和解释。 基于对这个主题的高度兴趣,我已经在Codeplex上设置了一个名为extensionoverflow的开源项目。 请将您的答案标记为Codeplex项目中的代码。 请发布完整的源代码,而不是链接。 Codeplex新闻: 24.08.2010 Codeplex页面现在位于: http ://extensionoverflow.codeplex.com/ 2008年11月11日XmlSerialize / XmlDeserialize现在已经实现并被unit testing 。 11.11.2008还有更多开发者的空间。 😉 立即join! 11.11.2008第三名贡献者join了ExtensionOverflow ,欢迎来到BKristensen 11.11.2008 FormatWith现在已经实现,并进行了unit testing 。 09.11.2008第二个贡献者join了ExtensionOverflow 。 欢迎来到chakrit 。 09.11.2008我们需要更多的开发者。 😉 09.11.2008 ThrowIfArgumentIsNull现已在Codeplex上实现并进行了unit testing 。

在cin之后使用getline(cin,s)

我需要下面的程序来获取用户input的全部内容,并将其input到string名称中: cout << "Enter the number: "; int number; cin >> number; cout << "Enter names: "; string names; getline(cin, names); 然而,在getline()命令之前使用cin >> number命令(我猜是这个问题),它不会允许我input名字。 为什么? 我听说过一个cin.clear()命令,但我不知道这是如何工作的,或者为什么这是必要的。

C#中variables名中@字符的用法/含义是什么?

我发现你可以用C#中的“@”字符来启动你的variables名。 在我的C#项目中,我使用的是用Java编写的Web服务(我添加了对我的项目的Web引用)。 WSDL中定义的一个接口对象有一个名为“params”的成员variables。 显然,这是C#中的一个保留字,所以你不能拥有一个名为“params”的成员variables。 生成的代理对象包含一个如下所示的属性: public ArrayList @params { get { return this.paramsField; } set { this.paramsField = value; } } 我search了VS 2008的c#文档,但无法find任何有关它。 也search谷歌没有给我任何有用的答案。 那么variables/属性名称中“@”字符的确切含义或用法是什么?

函数声明与原型的替代(K&R)C语法

这个C语法有什么用处 – 使用'K&R'样式函数声明? int func (p, p2) void *p; int p2; { return 0; } 我能够在Visual Studios 2010beta中编写这个 //yes the params are flipped void f() { void *v=0; func(5,v); } 我不明白。 这个语法有什么意义? 我可以写: int func (p, p2) int p2; { return 0; } //and write int func (p, p2) { return 0; } 它似乎指定的唯一的事情是它使用了多less个参数和返回types。 我猜没有types的参数是有点酷,但为什么允许它和函数声明后的int […]

如何获得最后插入的ID?

我有这个代码: string insertSql = "INSERT INTO aspnet_GameProfiles(UserId,GameId) VALUES(@UserId, @GameId)"; using (SqlConnection myConnection = new SqlConnection(myConnectionString)) { myConnection.Open(); SqlCommand myCommand = new SqlCommand(insertSql, myConnection); myCommand.Parameters.AddWithValue("@UserId", newUserId); myCommand.Parameters.AddWithValue("@GameId", newGameId); myCommand.ExecuteNonQuery(); myConnection.Close(); } 当我插入到这个表中时,我有一个名为GamesProfileId的auto_increment int主键列,我怎样才能得到最后一个插入一个之后,所以我可以使用该ID插入到另一个表?