.net

How do I use the IComparable interface?

╄→гoц情女王★ 提交于 2021-02-05 20:22:44
问题 I need a basic example of how to use the IComparable interface so that I can sort in ascending or descending order and by different fields of the object type I'm sorting. 回答1: Well, since you are using List<T> it would be a lot simpler to just use a Comparison<T> , for example: List<Foo> data = ... // sort by name descending data.Sort((x,y) => -x.Name.CompareTo(y.Name)); Of course, with LINQ you could just use: var ordered = data.OrderByDescending(x=>x.Name); But you can re-introduce this in

ChromeDriver does not exist in Selenium WebDriver C# test script

怎甘沉沦 提交于 2021-02-05 18:00:55
问题 I have come across a few people with the same issue that seemed to have solved the problem with System.addProperty("webdriver.chrome.driver", ".../chromedriver.exe"); before instantiating the driver. I have had little luck with this and am still getting the error that the file .../bin/Debug/chromedriver.exe does not exist. Has anyone had any luck getting this to run without putting it in the bin folder? Example code: System.Environment.SetEnvironmentVariable("webdriver.chrome.driver", @"c:

ChromeDriver does not exist in Selenium WebDriver C# test script

纵然是瞬间 提交于 2021-02-05 17:51:08
问题 I have come across a few people with the same issue that seemed to have solved the problem with System.addProperty("webdriver.chrome.driver", ".../chromedriver.exe"); before instantiating the driver. I have had little luck with this and am still getting the error that the file .../bin/Debug/chromedriver.exe does not exist. Has anyone had any luck getting this to run without putting it in the bin folder? Example code: System.Environment.SetEnvironmentVariable("webdriver.chrome.driver", @"c:

What is the difference between the KeyCode and KeyData properties on the .NET WinForms key event argument objects?

本秂侑毒 提交于 2021-02-05 14:33:12
问题 The two key event argument classes KeyEventArgs and PreviewKeyDownEventArgs each have two properties, KeyCode and KeyData , which are both of the enumeration type Keys. What is the difference between these two properties? Do the values in them ever differ from each other? If so, when and why? 回答1: KeyCode is an enumeration that represents all the possible keys on the keyboard. KeyData is the KeyCode combined with the modifiers (Ctrl, Alt and/or Shift). Use KeyCode when you don't care about

P/Invoke or C++/CLI for wrapping a C library

风格不统一 提交于 2021-02-05 13:37:48
问题 Have a moderate size (40-odd function) C API that needs to be called from a C# project. The functions logically break up to form a few classes that will be API presented to the rest of the project. Are there any objective reasons to prefer P/Invoke or C++/CLI for the interoperability underneath that API, in terms of robustness, maintainability, deployment, ...? The issues I could think of that might be, but aren't problematic are: C++/CLI will require an separate assembly, the P/Invoke

web.config and app.config machine-specific settings in git

女生的网名这么多〃 提交于 2021-02-05 12:55:30
问题 We have multiple teams of developers in different offices, and they need different values for a number of configuration setting in our projects' web.config and app.config files. We like to keep these configuration files checked in with a sensible set of default values, so that by checking out the trunk/master branch you have something working without needing to dig around for configuration files. Historically we've used Subversion, and specifically TortoiseSVN, and this provided an easy way

What exceptions does Newtonsoft.Json.DeserializeObject throw?

强颜欢笑 提交于 2021-02-05 12:52:10
问题 What exceptions does Newtonsoft.Json.DeserializeObject throw? I want to handle them. http://james.newtonking.com/json/help/?topic=html/M_Newtonsoft_Json_JsonConvert_DeserializeObject.htm#seeAlsoToggle 回答1: JSON.NET defines the following exceptions: JsonException JsonReaderException JsonSerializationException JsonWriterException JsonSchemaException Serialization or deserialization errors will typically result in a JsonSerializationException . 回答2: Note that Json.NET's error handling

What exceptions does Newtonsoft.Json.DeserializeObject throw?

北城余情 提交于 2021-02-05 12:51:22
问题 What exceptions does Newtonsoft.Json.DeserializeObject throw? I want to handle them. http://james.newtonking.com/json/help/?topic=html/M_Newtonsoft_Json_JsonConvert_DeserializeObject.htm#seeAlsoToggle 回答1: JSON.NET defines the following exceptions: JsonException JsonReaderException JsonSerializationException JsonWriterException JsonSchemaException Serialization or deserialization errors will typically result in a JsonSerializationException . 回答2: Note that Json.NET's error handling

How to convert hash data to original data? [duplicate]

邮差的信 提交于 2021-02-05 12:28:59
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Is it possible to decrypt md5 hashes? I hashed data with ComputeHash how can I learn original data from hashed data? private void btn_Hash_Click(object sender, EventArgs e) { HashAlgorithm ha = HashAlgorithm.Create(); Stream file = new FileStream(@"C:\temp\simetrik.txt", FileMode.Open, FileAccess.Read); hashClass.hash = ha.ComputeHash(file); listBox1.Items.Add(BitConverter.ToString(hashClass.hash)); } 回答1: You

How do I use reflection to call a generic method?

好久不见. 提交于 2021-02-05 11:48:08
问题 What's the best way to call a generic method when the type parameter isn't known at compile time, but instead is obtained dynamically at runtime? Consider the following sample code - inside the Example() method, what's the most concise way to invoke GenericMethod<T>() using the Type stored in the myType variable? public class Sample { public void Example(string typeName) { Type myType = FindType(typeName); // What goes here to call GenericMethod<T>()? GenericMethod<myType>(); // This doesn't