c#-4.0

How to skip first line and start reading file from second line in C#

风格不统一 提交于 2020-01-11 06:34:05
问题 How to start reading file from 2nd line skipping 1st line. This seems to work but is it best way to do so? using (StreamReader sr = new StreamReader(varFile, Encoding.GetEncoding(1250))) { string[] stringSeparator = new string[] { "\",\"" }; int i = 0; while (!sr.EndOfStream) { string line = sr.ReadLine(); //.Trim('"'); if (i > 0) { string[] values = line.Split(stringSeparator, StringSplitOptions.None); for (int index = 0; index < values.Length; index++) { MessageBox.Show(values[index].Trim('

Error registering plugins and/or workflows. Plug-in assembly does not contain the required types or assembly content cannot be updated

橙三吉。 提交于 2020-01-11 04:48:07
问题 I implemented one custom workflow in in Visual Studio 2010 using CRM 2011 Developer Toolkit. It was working fine with system generated namespace. But, when I changed the namespace of my project, its throwing an error "Error registering plugins and/or workflows. Plug-in assembly does not contain the required types or assembly content cannot be updated." while deploying it. And I have changed the namespace in .crmregister file, project properties and in source code. Then whats the problem here.

Usage of named parameters

ぐ巨炮叔叔 提交于 2020-01-11 03:26:30
问题 Sorry, if duplicate. I'm reading CLR via C#. Chapter "Parameters" starts with the explanation of optional and named parameters. So, can you give some example where using of named parameters has some benefits, or is it just the matter of style or habit? Do you personally use named parameters? 回答1: Named parameters are very useful when combined with optional parameters in C# 4. This allows you to avoid providing a lot of method overloads, and instead just have a single one. For example, instead

Multiple Date range comparison for overlap: how to do it efficiently?

喜欢而已 提交于 2020-01-10 14:19:28
问题 To check for overlap in two different dateranges, {Start1, End1} and {Start2, End2} I am checking: if ((Start1 <= End2) && (End1 >= Start2)) { //overlap exists } The question is, what is a good way to compare overlaps if I had let's say five dateranges? . checking to see if any of them don't overlap each other? If I have multiple date ranges, how to find if any of these ranges are overlapping? 回答1: To find if all are overlapping static bool Overlap(params Tuple<DateTime, DateTime>[] ranges) {

Sort List<string> like Excel columns sort

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-10 05:20:23
问题 Please consider this List: "A", "C", "AB", "AD", "N", "Z", "AC" I want to sort this string (That are being Excel column) like Excel Column Sorting. I want the result like this: "A", "C", "N", "Z", "AB", "AC", "AD" Is it possible using LINQ OrderBy? What is the best approach? Thanks 回答1: Update : Thanks @JeppeStigNielsen for correct comment, I add StringComparer.Ordinal to support in all cultures: var result = List.OrderBy(p=>p.Length).ThenBy(p=>p,StringComparer.Ordinal); 回答2: First order by

Set Maximum Memory Usage C#

只愿长相守 提交于 2020-01-10 05:06:35
问题 I have an application that must use a library that I didn't write and I don't have the power to change it. Basically there is a memory leak, so the long it runs, the more it leaks; it basically just writes stale pagefiles that I don't have the power to delete. The memory leak doesn't actually cause the program to crash, it just simply eats up all the memory. When it is using all the system's memeory, the OS will just start deleting the old page files and everything runs fine. If I run my app

Getting FileHelpers 2.0 to handle CSV files with excess commas

非 Y 不嫁゛ 提交于 2020-01-10 04:10:07
问题 I am currently using the FileHelpers library (v2.0.0.0) to parse a CSV file. The CSV file is mapped to a class that has a handful of public properties, let's say there are N . The problem is that, by default, FileHelpers doesn't seem to correctly handle cases where the user specifies a CSV file that has more than N-1 commas. The remaining commas just get appended to the last property value. I figured this must be configurable via FileHelpers' attributes, but I didn't see anything that would

add data to existing xml file using linq

痞子三分冷 提交于 2020-01-10 01:45:32
问题 I am a .net beginner. I need to add some data to xml file the xml file is: <stock> --- 1st level /* i dont want to create this because this exists */ <items> -- 2nd level <productname>Toothpaste</productname> <brandname>Colgate</brandname> <quantity>12</quantity> <price>10</price> </items> <items> <productname>Toothpaste</productname> <brandname>Pepsodent</brandname> <quantity>20</quantity> <price>12</price> </items> </stock> I need to add productname --> Toothpaste brandname --> CloseUp

What is the practical use of “dynamic” variable in C# 4.0?

喜你入骨 提交于 2020-01-09 07:14:33
问题 What is their use if when you call the method, it might not exist? Does that mean that you would be able to dynamically create a method on a dynamic object? What are the practical use of this? 回答1: You won't really be able to dynamically create the method - but you can get an implementation of IDynamicMetaObject (often by extending DynamicObject ) to respond as if the method existed . Uses: Programming against COM objects with a weak API (e.g. office) Calling into dynamic languages such as

LINQ OrderBy or Sort does not order correctly for integer string list?

岁酱吖の 提交于 2020-01-07 09:42:59
问题 I've been working on ordering of object which need to be done on the string which has integer value like "1","2". But LINQ OrderBy or SOrt inplace itself not ordering correctly : Following code can reproduce my issue : var listStr = new List<string>() { "1", "100", "12" }; var sortedList = listStr.OrderBy(x => x); var desList = listStr.OrderByDescending(x => x); Here, SortedList is in following order : "1","100","12" and deslist is "12","100", "12" I am confused with the way with string