.net

Why is OrderBy which returns IOrderedEnumerable<T> much faster than Sort?

a 夏天 提交于 2021-02-04 14:30:14
问题 This is a follow up of this excellent question C# Sort and OrderBy comparison. I will use the same example: List<Person> persons = new List<Person>(); persons.Add(new Person("P005", "Janson")); persons.Add(new Person("P002", "Aravind")); persons.Add(new Person("P007", "Kazhal")); The methods in contention are: persons.Sort((p1, p2) => string.Compare(p1.Name, p2.Name, true)); //and persons.OrderBy(n => n.Name); Let me start by saying that I understand there isn't any significant performance

Why is OrderBy which returns IOrderedEnumerable<T> much faster than Sort?

♀尐吖头ヾ 提交于 2021-02-04 14:29:06
问题 This is a follow up of this excellent question C# Sort and OrderBy comparison. I will use the same example: List<Person> persons = new List<Person>(); persons.Add(new Person("P005", "Janson")); persons.Add(new Person("P002", "Aravind")); persons.Add(new Person("P007", "Kazhal")); The methods in contention are: persons.Sort((p1, p2) => string.Compare(p1.Name, p2.Name, true)); //and persons.OrderBy(n => n.Name); Let me start by saying that I understand there isn't any significant performance

Windows service with FileSystemWatcher and Timer - making sure everything gets disposed

ⅰ亾dé卋堺 提交于 2021-02-04 14:13:33
问题 I have created a C# Windows Service application that starts a FileSystemWatcher to monitor a directory for the creation of a file. When the file is found I instantiate a custom class that parses the file (CSV) and calls a web service with it's contents. The service is somewhat asynchronous and returns a unique number which must be used for subsequent calls to check its progress. In my process class I create a timer to continually check to see if the job is finished. I am dispose ing and close

Got hit by an OverflowException

天涯浪子 提交于 2021-02-04 13:14:27
问题 In the Method below on the last line I'm always getting an exception: System.OverflowException: Value was either too large or too small for an Int32. I can't really explain why because I'm checking explicitly for that: private Int32 ConvertValue(double value) { if (value > Int32.MaxValue) { Console.WriteLine("Couldn't convert value " + value + " to Int32"); return Int32.MaxValue; } else if (value < Int32.MinValue) { Console.WriteLine("Couldn't convert value " + value + " to Int32"); return

Got hit by an OverflowException

时光总嘲笑我的痴心妄想 提交于 2021-02-04 13:14:25
问题 In the Method below on the last line I'm always getting an exception: System.OverflowException: Value was either too large or too small for an Int32. I can't really explain why because I'm checking explicitly for that: private Int32 ConvertValue(double value) { if (value > Int32.MaxValue) { Console.WriteLine("Couldn't convert value " + value + " to Int32"); return Int32.MaxValue; } else if (value < Int32.MinValue) { Console.WriteLine("Couldn't convert value " + value + " to Int32"); return

Cannot apply Operator '<' to operands of type T and T

走远了吗. 提交于 2021-02-04 12:12:00
问题 so here's my code public void BubbleSort<T>(T[] array) where T : IComparable<T> { for (int i = 0; i < array.Length; i++) { for (int j = 1; j < array.Length; j++) { if (array[j] < array[j - 1]) { } } } } and before you shoot be down for not searching. I have searched and one of the answers here on SO said to use an icomparable interface to solve the problem. unfortunately i am not going anywhere with this error. 回答1: It looks like you're expecting the IComparable<T> constraint to allow you to

Cannot apply Operator '<' to operands of type T and T

别说谁变了你拦得住时间么 提交于 2021-02-04 12:11:05
问题 so here's my code public void BubbleSort<T>(T[] array) where T : IComparable<T> { for (int i = 0; i < array.Length; i++) { for (int j = 1; j < array.Length; j++) { if (array[j] < array[j - 1]) { } } } } and before you shoot be down for not searching. I have searched and one of the answers here on SO said to use an icomparable interface to solve the problem. unfortunately i am not going anywhere with this error. 回答1: It looks like you're expecting the IComparable<T> constraint to allow you to

How can I get a list of built-in routed events in WPF

亡梦爱人 提交于 2021-02-04 11:38:05
问题 I'm just starting out with WPF and need some help with routed events. I have added a datagrid with some animation, but i can't seem to find anywhere that shows me a list of routed events to use on the datagrid, or any other control for that matter. Seems to be a guessing game so far. I thought the datagrid standard events, such as CellEditEnding, was it but they are not as it says "Invalid event name". The example I copied used a MouseEnter routed event, but i don't know what else there is

How can I get a list of built-in routed events in WPF

风格不统一 提交于 2021-02-04 11:37:18
问题 I'm just starting out with WPF and need some help with routed events. I have added a datagrid with some animation, but i can't seem to find anywhere that shows me a list of routed events to use on the datagrid, or any other control for that matter. Seems to be a guessing game so far. I thought the datagrid standard events, such as CellEditEnding, was it but they are not as it says "Invalid event name". The example I copied used a MouseEnter routed event, but i don't know what else there is

Build and publish C# .NET Web App via command line

喜欢而已 提交于 2021-02-04 10:54:21
问题 I need to be able to generically and separately build and publish C# ASP.NET Web Applications. Ideally, I would like to use MSBuild to build the application, and if that succeeds, I would like to simply publish the site preferably solely with file copy. Currently, I am able to build web application quite easily with MSBuild, but it is the publishing that is causing confusion. After the build, the binaries sit in the bin folder, but I am not sure what files to copy. What would be a good way to