c#-3.0

Why does the Equals implementation for anonymous types compare fields?

試著忘記壹切 提交于 2019-12-17 02:31:59
问题 I'm just wondering why designers of the language decided to implement Equals on anonymous types similarly to Equals on value types. Isn't it misleading? public class Person { public string Name { get; set; } public int Age { get; set; } } public static void ProofThatAnonymousTypesEqualsComparesBackingFields() { var personOne = new { Name = "Paweł", Age = 18 }; var personTwo = new { Name = "Paweł", Age = 18 }; Console.WriteLine(personOne == personTwo); // false Console.WriteLine(personOne

DevExpress TreeList Control

為{幸葍}努か 提交于 2019-12-14 04:26:14
问题 I need to display the xml data in the treelist control. I have one root node, one Child node and further four children for this child node. I am not able to display it in the treelist. I am using the dataset.readXml method for reading the xml file and giving dataset as a datasource. Here is the code I am following: DataSet dataSet = new DataSet(); dataSet.ReadXml(@"C:\foldersettings.xml"); treeList2.DataSource = dataSet; treeList2.PopulateColumns(); treeList2.BestFitColumns(); treeList2

Prioritising Event Handlers

こ雲淡風輕ζ 提交于 2019-12-14 03:56:00
问题 I have the following code where I am handling an event twice. However I always want to ensure that mynewclass always handles the event first and then the local event handler code fires. I understand the MyClass event should fire first as that is the one created first but because the thread and enqueuing is taking place, I think its taking too long and its doing something in myhandleeventlocal before I want it to do that. Any way I can wait for it to happen? public MyMainClass { private

Aggregating different file CSV

这一生的挚爱 提交于 2019-12-14 03:36:07
问题 I'm beginner in C# and I don't know the API in details. I would like to write a one .csv that contains a single day from each of those files, and contains the data that was there in each file. 回答1: You have to use plain loops in C#3.0, you could fill a Dictionary for example: string dir = @"C:\DirectoryName"; string[] files = Directory.GetFiles(dir, "*.csv", SearchOption.TopDirectoryOnly); var dateFiles = new Dictionary<DateTime, List<string>>(); foreach (string file in files) { string fn =

How to convert fractional years (say 1.25 years) to number of days

半腔热情 提交于 2019-12-14 03:31:59
问题 I have a table that shows periods like 1 year to 10 years. I want to calculate number of days (approximately 365 days in a year and no need to include leap year). If it was just years, it is easy to calculate days ( like 2 years = 2*365 days). But how can convert for 1.5 years or 1.75 years into days? what is the efficient way to calculate days if the years are specified in terms of fractional years. Thanks nath 回答1: Try: float year = 1.5; int days = Math.Round(year * 365); 回答2: Since the

Allow Numbers and Special Characters only not alphabets

烂漫一生 提交于 2019-12-14 03:27:43
问题 i have a textbox, in that i want to restrict the alphabets only, that is it will accept only numbers and special charcaters not alphabets.. i had tried the below java script ,but it will not working .... <script type="text/javascript"> //Function to allow only numbers to textbox function validate(key) { //getting key code of pressed key var keycode = (key.which) ? key.which : key.keyCode; //comparing pressed keycodes if (keyCode >= 65 && keyCode <= 90) { return false; } } </script> and in the

Advantages of UI design in XAML

穿精又带淫゛_ 提交于 2019-12-13 16:21:47
问题 In WPF i can make my UI using .NET 2.0 style like designer.cs, my question is what are the advantages of using XAML for UI design instead of code. 回答1: The main advantage is that if you keep a clean separation of markup and code (e.g. by applying the MVVM pattern), you can concentrate on the behavior of the application (i.e. the code) and let professional graphic designers worry about applying the look and feel of the application. These two tasks can even be worked on in parallel by two

In WPF based desktop app touch drag and drop is working on window 7 but not on Window 8

[亡魂溺海] 提交于 2019-12-13 14:02:18
问题 I am developing WPF based desktop application. I have Implemented Touch drag and drop functionality. Its working perfectly on Window 7 . But on window 8 its not working. In window 8 , when i am doing double tap on any file(image , mp3 or video) and then drag the content , then its working fine. But this behaviour is wrong, I want the normal behaviour as working on window 7 (Simple touch and drag the file) Please help me. 来源: https://stackoverflow.com/questions/30918559/in-wpf-based-desktop

Generate random words

橙三吉。 提交于 2019-12-13 10:13:14
问题 apple, mango, papaya, banana, guava, pineapple - How to generate these words randomly (one by one) using c# ? Please help me to generate the words randomly from the list of words I have.. 回答1: Random rnd = new Random(); string GetRandomFruit() { string[] fruits = new string[] { "apple", "mango", "papaya", "banana", "guava", "pineapple" }; return fruits[rnd.Next(0,fruits.Length)]; } 回答2: You can get "random sorting" with LINQ's OrderBy method and using Guid s var words = new [] {"apple",

Could not load file or assembly 'or one of its dependencies. The system cannot find the file specified

穿精又带淫゛_ 提交于 2019-12-13 05:13:45
问题 Hope someone could help me with this. I'm referencing a dll proxy "MonitorProxy" in a webservice project which is hosted on a windows service host. When I debug the service host I receive this exception: Could not load file or assembly 'MonitorProxy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. Although I'm sure that the MonitorProxy.dll is correcltly located and that the webservice reference refers to its