c#-4.0

Null pointer test performance

℡╲_俬逩灬. 提交于 2020-01-24 02:46:08
问题 What is the performance of testing whether a reference-type variable in C# is a null-pointer (like if (x == null) ...) compared to testing for an integer being smaller than zero or even a bool being false? Are there other issues know regarding such null-pointer tests , e.g. is garbadge produced ? I do hundred of these tests for every frame of a game and I was wondering if these could cause problems or could be implemented more efficiently? 回答1: Nullity tests are likely to be equivalent to

How to iterate over an array of dynamic type in C# 4.0?

半腔热情 提交于 2020-01-24 02:32:31
问题 Hi I have an array of dynamic type which i want to iterate through. But when i say arrayObject.lenght, i get following error: 'object' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'object' could be found how do i iterate over the array? [Update] I post a custom json object using jquery ajax and i have written a model binder for untyped JSON. Here is a screenshot: 回答1: Found the solution: foreach (dynamic item in cartJsonObject)

Intersect two List<> in C#

非 Y 不嫁゛ 提交于 2020-01-23 18:47:47
问题 I have two List<T> objects that I would like to intersect, but I get errors when trying. // Make the Keys in the Dictionary<Load, double> _loads to form a List<Load> List<Load> l1 = _loads.Keys.ToList(); // Get a list from my element. List<Load> l2 = element.ListLoads; // Intersect List<Load> loads = (List<Load>)l1.Intersect<Load>(l2); 回答1: Intersect<T> returns an IEnumerable<T>, so the correct way is: var loads = l1.Intersect(l2).ToList(); ToList<T> creates a List<T> from an IEnumerable<T> .

Could not able to get X509Certificate2 certificate by code C#

喜欢而已 提交于 2020-01-23 11:27:35
问题 I want to find certificate from my store but using following code i could not able to get certificate. It always return null. What's wrong with my code? Update: I have copied my certificate thumbprint by exploring store object and compare it with my thumbprint string and it return false! I think issue of interpreting string in VS2010 IDE or copy paste problem you can see that below in fig. because of this it should ignore the certificate from the list. Have anyone faced this type of issue

How To change Command Text and ImageButton of ItemTemplate in TemplateField

一个人想着一个人 提交于 2020-01-23 10:44:26
问题 I have a column that has an ImageButton. my database field has bit data type. I want when my record has true value in that column show True.jpg and my command become MakeFalse and when it has false value show False.jpg and my command become MakeTrue . How I can do this?Is it possible to do it with one TemplateField ? thanks 回答1: You could include two ImageButtons in a TemplateField and evaluate Visible from your bit_field <asp:TemplateField HeaderText="YourField"> <ItemTemplate> <asp

How To change Command Text and ImageButton of ItemTemplate in TemplateField

佐手、 提交于 2020-01-23 10:44:04
问题 I have a column that has an ImageButton. my database field has bit data type. I want when my record has true value in that column show True.jpg and my command become MakeFalse and when it has false value show False.jpg and my command become MakeTrue . How I can do this?Is it possible to do it with one TemplateField ? thanks 回答1: You could include two ImageButtons in a TemplateField and evaluate Visible from your bit_field <asp:TemplateField HeaderText="YourField"> <ItemTemplate> <asp

generate xml files based on my c# classes

南笙酒味 提交于 2020-01-22 18:42:12
问题 i have xml file that i need to update each and every time as per new client requirement. most of the time xml is not proper because of manual updation of xml file. I am thinking to write a program (web/windows) where proper validation is provided. and based on the input from ui I will going to create xml file. below is my sample xml file. <community> <author>xxx xxx</author> <communityid>000</communityid> <name>name of the community</name> <addresses> <registeredaddress> <addressline1>xxx<

Trying to filter on a Nullable type using Expression Trees

拈花ヽ惹草 提交于 2020-01-22 16:53:06
问题 I have pasted my entire test app below. It's fairly compact so I am hoping that it's not a problem. You should be able to simply cut and paste it into a console app and run it. I need to be able to filter on any one or more of the Person objects' properties, and I don't know which one(s) until runtime. I know that this has beed discussed all over the place and I have looked into and am also using tools such as the PredicateBuilder & Dynamic Linq Library but the discussion aroung them tends to

Trying to filter on a Nullable type using Expression Trees

扶醉桌前 提交于 2020-01-22 16:52:50
问题 I have pasted my entire test app below. It's fairly compact so I am hoping that it's not a problem. You should be able to simply cut and paste it into a console app and run it. I need to be able to filter on any one or more of the Person objects' properties, and I don't know which one(s) until runtime. I know that this has beed discussed all over the place and I have looked into and am also using tools such as the PredicateBuilder & Dynamic Linq Library but the discussion aroung them tends to

Parallel.Invoke - Exception handling

坚强是说给别人听的谎言 提交于 2020-01-22 14:52:10
问题 My code runs 4 function to fill in information (Using Invoke) to a class such as: class Person { int Age; string name; long ID; bool isVegeterian public static Person GetPerson(int LocalID) { Person person; Parallel.Invoke(() => {GetAgeFromWebServiceX(person)}, () => {GetNameFromWebServiceY(person)}, () => {GetIDFromWebServiceZ(person)}, () => { // connect to my database and get information if vegeterian (using LocalID) .... if (!person.isVegetrian) return null .... }); } } My question is: I