c#-4.0

Create Json dynamically in c#

柔情痞子 提交于 2020-12-24 05:09:21
问题 I need to create a Json object dynamically by looping through columns. so declaring an empty json object then add elements to it dynamically. eg: List<String> columns = new List<String>{"FirstName","LastName"}; var jsonObj = new {}; for(Int32 i=0;i<columns.Count();i++) jsonObj[col[i]]="Json" + i; And the final json object should be like this: jsonObj={FirstName="Json0", LastName="Json1"}; 回答1: [TestFixture] public class DynamicJson { [Test] public void Test() { dynamic flexible = new

Create Json dynamically in c#

一笑奈何 提交于 2020-12-24 05:04:51
问题 I need to create a Json object dynamically by looping through columns. so declaring an empty json object then add elements to it dynamically. eg: List<String> columns = new List<String>{"FirstName","LastName"}; var jsonObj = new {}; for(Int32 i=0;i<columns.Count();i++) jsonObj[col[i]]="Json" + i; And the final json object should be like this: jsonObj={FirstName="Json0", LastName="Json1"}; 回答1: [TestFixture] public class DynamicJson { [Test] public void Test() { dynamic flexible = new

Create Json dynamically in c#

我只是一个虾纸丫 提交于 2020-12-24 05:04:28
问题 I need to create a Json object dynamically by looping through columns. so declaring an empty json object then add elements to it dynamically. eg: List<String> columns = new List<String>{"FirstName","LastName"}; var jsonObj = new {}; for(Int32 i=0;i<columns.Count();i++) jsonObj[col[i]]="Json" + i; And the final json object should be like this: jsonObj={FirstName="Json0", LastName="Json1"}; 回答1: [TestFixture] public class DynamicJson { [Test] public void Test() { dynamic flexible = new

C# string to Decimal On All style or Culture

喜你入骨 提交于 2020-12-15 06:10:47
问题 Hi I want to find if there is any better way to parse the string to Decimal which covers various format $1.30 £1.50 €2,50 2,50 € 2.500,00 € I see a lot of examples using culture to convert . & , . But in my case, I don't have anything to identify the culture. This display field I get from the client and I need to extract the value. I tried following (which didn't work for all scenario) but would like to know if we have any best way to handle this. Decimal.Parse(value,NumberStyles.Currency |

Getting exception when working with list and parallel loops

北慕城南 提交于 2020-12-14 06:37:13
问题 I have written a code like following below: Parallel.ForEach(filteredList, (f) => { var conditionMatchCount = itm.AsParallel().Max(i => // One point if ID matches ((i.ItemID == f.ItemID) ? 1 : 0) + // One point if ID and QuantitySold match ((i.ItemID == f.ItemID && i.QuantitySold == f.QuantitySold) ? 1 : 0) ); // Item is missing if (conditionMatchCount == 0) { ListToUpdate.Add(f); missingList.Add(f); } // Item quantity is different else if (conditionMatchCount == 1) { ListToUpdate.Add(f); } }

Getting exception when working with list and parallel loops

萝らか妹 提交于 2020-12-14 06:36:04
问题 I have written a code like following below: Parallel.ForEach(filteredList, (f) => { var conditionMatchCount = itm.AsParallel().Max(i => // One point if ID matches ((i.ItemID == f.ItemID) ? 1 : 0) + // One point if ID and QuantitySold match ((i.ItemID == f.ItemID && i.QuantitySold == f.QuantitySold) ? 1 : 0) ); // Item is missing if (conditionMatchCount == 0) { ListToUpdate.Add(f); missingList.Add(f); } // Item quantity is different else if (conditionMatchCount == 1) { ListToUpdate.Add(f); } }

Is there any MathParser that parse a mathematical string expression containing average function like avg(value1 + value2 + value3) + …?

99封情书 提交于 2020-12-13 11:12:24
问题 I have a text box and I simply type a mathematical expression like: sin(1) + 2 + cos(5) + sqrt(5) and pass it to my MathParser class object and it returns me the result. I went through the class and found that for mathematical operators like +, -, *, /; there is a function which returns 2 because these operations can be performed only between two parameters like '1 + 2' and mathematical functions like sin, cos, tan, abs, sqrt; have a single parameter like sin(param), etc. so it returns 1. Now

How to check programatically if keyboard is connected or not?

断了今生、忘了曾经 提交于 2020-12-05 11:05:04
问题 I am developing an application with C# winforms. Our application is going to be installed on win8 surface(touch screen device). We want to check if a keyboard is connected via USB then our app will not show soft keypad otherwise it will show. Many methods are avaliable to check for WinRT but none for winforms C#. Please let me know if my question is not clear. Thanks in advance. 回答1: I just wrote this and tested on W8: ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select

How to check programatically if keyboard is connected or not?

孤人 提交于 2020-12-05 11:04:49
问题 I am developing an application with C# winforms. Our application is going to be installed on win8 surface(touch screen device). We want to check if a keyboard is connected via USB then our app will not show soft keypad otherwise it will show. Many methods are avaliable to check for WinRT but none for winforms C#. Please let me know if my question is not clear. Thanks in advance. 回答1: I just wrote this and tested on W8: ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select

How to check programatically if keyboard is connected or not?

狂风中的少年 提交于 2020-12-05 11:04:35
问题 I am developing an application with C# winforms. Our application is going to be installed on win8 surface(touch screen device). We want to check if a keyboard is connected via USB then our app will not show soft keypad otherwise it will show. Many methods are avaliable to check for WinRT but none for winforms C#. Please let me know if my question is not clear. Thanks in advance. 回答1: I just wrote this and tested on W8: ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select