c#-2.0

Parse integer from string containing letters and spaces - C#

99封情书 提交于 2019-12-10 14:49:24
问题 What is the most efficient way to parse an integer out of a string that contains letters and spaces? Example: I am passed the following string: "RC 272". I want to retrieve 272 from the string. I am using C# and .NET 2.0 framework. 回答1: Since the format of the string will not change KISS: string input = "RC 272"; int result = int.Parse(input.Substring(input.IndexOf(" "))); 回答2: A simple regex can extract the number, and then you can parse it: int.Parse(Regex.Match(yourString, @"\d+").Value,

how List<T> does not implement Add(object value)?

岁酱吖の 提交于 2019-12-10 14:42:37
问题 I believe it's pretty stupid, and I am a bit embarrassed to ask this kind of question, but I still could not find the answer: I am looking at the class List<T> , which implemetns IList . public class List<T> : IList one of the methods included in Ilist is int Add(object value) I understand that List<T> should not expose that method (type safety...), and it really does not. But how can it be? mustnt class implement the entire interface? 回答1: I believe that this (interface) method is

ListBox doesn't show changes to DataSource

荒凉一梦 提交于 2019-12-10 13:29:00
问题 I thought this was a simple problem, but I can't find any information on the web. I'm binding a ListBox to a List using BindingSource like so: List<Customer> customers = MyMethodReturningList(); BindingSource customersBindingSource = new BindingSource(); customersBindingSource.DataSource = customers; customersListBox.DataSource = customersBindingSource; Now, when I add or delete from customers list, my ListBox gets updated (even without using ResetBindings on BindingSource ), but if I change

Does Event logger in C# needs admin privileges to write logs into Windows Event Viewer?

[亡魂溺海] 提交于 2019-12-10 12:48:24
问题 In my C# application I am using EventLog class to log messages. It works perfectly fine on my machine but doesnt really works on client machine. Client machine configuration is different than my machine. My machine has Vista OS whereas client has Windows 2003 OS. I have admin rights on my machine whereas on client machine my application runs under non-admin user previleges. On client machine I get error as Faulting application , version ,faulting module kernel32.dll My application stopped

Process.WaitForExit not waiting

跟風遠走 提交于 2019-12-10 11:29:20
问题 I have the following code and the WaitForExit method is not waiting. It just runs the command and moves on to the next statement. The command is to unintall an application and the parms are for the uninstall command. The uninstall runs fine but I need the uninstall to finish before moving on...it's not blocking. ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = commandName; startInfo.Arguments = parms; Process process = Process.Start(startInfo); process.WaitForExit();

How make two way binding numericUpDown to member class

一笑奈何 提交于 2019-12-10 09:31:53
问题 I need twoway binding configClass.RaMsize to numericUpDown. BindField(this.upDownRamSize, "Value", configClass, "RaMsize");//all right this.upDownRamSize.Value = 1213;// configClass.RaMsize - not change - it's bad! Method: public static void BindField(Control control, string propertyName, object dataSource, string dataMember) { Binding bd; for (int index = control.DataBindings.Count - 1; (index == 0); index--) { bd = control.DataBindings[index]; if (bd.PropertyName == propertyName) control

Filter List<> object without using foreach loop in C#2.0

我是研究僧i 提交于 2019-12-10 02:42:57
问题 How we can filter the object in List<> in C#? 回答1: Let's say we have a List<string> and you want only the items where the length of the string is greater than 5. The code below will return a List<string> with the results: List<string> myList = new List<string>(); myList.Add("hello"); myList.Add("world!"); myList.Add("one"); myList.Add("large!!"); List<string> resultList = myList.FindAll(delegate(string s) { return s.Length > 5; }); resultList will containt 'world!' and 'large!!'. This example

How to get a ReadOnlyCollection<T> of the Keys in a Dictionary<T, S>

旧巷老猫 提交于 2019-12-09 16:45:14
问题 My class contains a Dictionary<T, S> dict , and I want to expose a ReadOnlyCollection<T> of the keys. How can I do this without copying the Dictionary<T, S>.KeyCollection dict.Keys to an array and then exposing the array as a ReadOnlyCollection ? I want the ReadOnlyCollection to be a proper wrapper, ie. to reflect changes in the underlying Dictionary, and as I understand it copying the collection to an array will not do this (as well as seeming inefficient - I don't actually want a new

Send email with attchement using System.Net.Mail

杀马特。学长 韩版系。学妹 提交于 2019-12-09 16:37:41
问题 I am using System.Net.Mail to send emails through my application. I was trying to send emails with the attachments with following code. Collection<string> MailAttachments = new Collection<string>(); MailAttachments.Add("C:\\Sample.JPG"); mailMessage = new MailMessage(); foreach (string filePath in emailNotificationData.MailAttachments) { FileStream fileStream = File.OpenWrite(filePath); using (fileStream) { Attachment attachment = new Attachment(fileStream, filePath); mailMessage.Attachments

How to make form topmost to the application only?

牧云@^-^@ 提交于 2019-12-09 11:30:48
问题 I am making excel add-in in which clicking on menu item or toolbar button, Form opened. I have set form's topmost to true but it remain topmost to all applications of windows xp. I just need to remain topmost to Microsoft Excel only. I have choosed project in Visual Studio 2008, in Excel ->2003. Please tell me how to do that with any way ........ 回答1: You can set your Form's owner to be the Microsoft Excel window. In Windows owned windows are always displayed above their owner. Dialogs and