Tag: C#的

如何从列表<string>中find所有重复?

我有一个List<string>有一些单词重复。 我需要find所有重复的单词。 有什么窍门让他们全部?

互相引用的不可变对象?

今天,我正试图围绕不可变对象进行相互引用。 我得出的结论是,如果不使用懒惰的评估,你不可能做到这一点,但在我写这个(在我看来)有趣的代码的过程中。 public class A { public string Name { get; private set; } public BB { get; private set; } public A() { B = new B(this); Name = "test"; } } public class B { public AA { get; private set; } public B(A a) { //a.Name is null A = a; } […]

“strlen(s1) – strlen(s2)”永远不会小于零

我目前正在编写一个C程序,需要经常比较string长度,所以我写了下面的帮助函数: int strlonger(char *s1, char *s2) { return strlen(s1) – strlen(s2) > 0; } 我注意到,即使当s1长度比s2短,函数也会返回true。 有人能解释这种奇怪的行为吗?

在string集合中search最快的方法

问题: 我有一个约12万个用户(string)的文本文件,我想存储在一个集合中,然后在该集合上执行search。 每次用户更改文本TextBox的文本时都会发生search方法,并且结果应该是包含 TextBox本的string。 我不必更改列表,只需将结果ListBox到列表框中即可。 我到目前为止所尝试的是: 我尝试了两个不同的集合/容器,我从一个外部文本文件(当然是一次)转储string条目: List<string> allUsers; HashSet<string> allUsers; 通过以下的LINQ查询: allUsers.Where(item => item.Contains(textBox_search.Text)).ToList(); 我的search事件(用户更改search文本时触发): private void textBox_search_TextChanged(object sender, EventArgs e) { if (textBox_search.Text.Length > 2) { listBox_choices.DataSource = allUsers.Where(item => item.Contains(textBox_search.Text)).ToList(); } else { listBox_choices.DataSource = null; } } 结果: 两者都给了我一个很差的响应时间(每个按键之间大约1-3秒)。 题: 你认为我的瓶颈在哪里? 我用过的集合? search方法? 都? 我怎样才能获得更好的性能和更stream畅的function?

如何在ASP.net中的div文件后面的代码中修改样式?

目前我正在尝试修改基于从我的aspx页面后面的代码中的数据库表中获得的信息的CSS样式属性。 以简化的forms,以下基本上是我想要做的,但我得到的错误。 这是我的代码: ASPX: <div id="testSpace" runat="server"> Test </div> 代码后面: testSpace.Style = "display:none;" testSpace.Style("display") = "none"; 任何帮助,将不胜感激。 谢谢!

如何在C#中获取string的ASCII值

我想要在C#中的string中获取字符的ASCII值。 如果我的string的值是“9quali52ty3”,我想要一个数组,每个11个字符的ASCII值。 我如何获得C#中的ASCII值?

我如何使Visual Studio的构build非常冗长?

我需要获取每个标志,Visual Studio二进制文件生成过程中使用的每个开关。 我试图通过使用vcbuild来获得详细的输出,但是我没有办法。 为了查看Visual Studio为我执行的所有操作,我需要做些什么? 没有必要在构build窗口中获取输出。 任何地方都可以。

我怎样才能拆分和修整一个string成部分都在一行?

我想分割这一行: string line = "First Name ; string ; firstName"; 进入他们的修剪版本的数组: "First Name" "string" "firstName" 我怎么能做到这一切在一条线上? 以下给我一个错误“不能转换typesvoid”: List<string> parts = line.Split(';').ToList().ForEach(p => p.Trim());

为什么double.NaN不等于自己?

谁可以给我解释一下这个? 在C#中double.NaN不等于double.NaN bool huh = double.NaN == double.NaN; // huh = false bool huh2 = double.NaN >= 0; // huh2 = false bool huh3 = double.NaN <= 0; // huh3 = false 什么常数,我可以比较一个doubleNNN,并成为现实?

从HttpResponseMessage获取内容/消息

我试图得到HttpResponseMessage的内容。 它应该是: {"message":"Action '' does not exist!","success":false} ,但是我不知道如何从HttpResponseMessage中获取它。 HttpClient httpClient = new HttpClient(); HttpResponseMessage response = await httpClient.GetAsync("http://****?action="); txtBlock.Text = Convert.ToString(response); //wrong! 在这种情况下,txtBlock将有价值: StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Vary: Accept-Encoding Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Date: Wed, 10 Apr 2013 20:46:37 GMT Server: Apache/2.2.16 Server: (Debian) X-Powered-By: PHP/5.3.3-7+squeeze14 Content-Length: 55 […]