nullable

XmlSerializer and nullable attributes

末鹿安然 提交于 2019-12-03 06:36:47
问题 I have a class with numerous Nullable<T> properties which I want to be serializable to XML as attributes. This is apparently a no-no as they are considered 'complex types'. So, instead I implement the *Specified pattern, where I create an addition *Value and *Specified property as follows: [XmlIgnore] public int? Age { get { return this.age; } set { this.age = value; } } [XmlAttribute("Age")] public int AgeValue { get { return this.age.Value; } set { this.age = value; } } [XmlIgnore] public

testing inequality with columns that can be null

梦想的初衷 提交于 2019-12-03 06:35:44
So, I asked a question this morning, which I did not phrase correctly, so I got a lot of responses as to why NULL compared to anything will give NULL/FALSE. My actual question was, what is the time honored fashion in which db guys test inequalities for two columns that can both be NULL. My question is the exact opposite of this question . The requirements are as follows, A and B are two columns: a) if A and B are both NULL, they are equal, return FALSE b) if A and B are both not NULL, then return A<>B c) if either A or B are NULL, they are not equal, return TRUE Depending on the data type and

How can I convert decimal? to decimal

巧了我就是萌 提交于 2019-12-03 06:28:25
问题 may be it is a simple question but I'm try all of conversion method! and it still has error! would you help me? decimal? (nullable decimal) to decimal 回答1: Try using the ?? operator: decimal? value=12; decimal value2=value??0; 0 is the value you want when the decimal? is null. 回答2: There's plenty of options... decimal? x = ... decimal a = (decimal)x; // works; throws if x was null decimal b = x ?? 123M; // works; defaults to 123M if x was null decimal c = x.Value; // works; throws if x was

Java check if boolean is null

拥有回忆 提交于 2019-12-03 06:27:56
问题 How do you check if a boolean is null or not? So if I know "hideInNav" is null. How do I stop it from further executing? Something like the below doesn't seem to work but why? boolean hideInNav = parent.getProperties().get("hideInNav", false); String hideNavigation = hideInNav != null ? hideInNav : ""; 回答1: boolean can only be true or false because it's a primitive datatype (+ a boolean variables default value is false ). You can use the class Boolean instead if you want to use null values.

Alternatives to nullable types in C#

安稳与你 提交于 2019-12-03 05:55:50
I am writing algorithms that work on series of numeric data, where sometimes, a value in the series needs to be null. However, because this application is performance critical, I have avoided the use of nullable types. I have perf tested the algorithms to specifically compare the performance of using nullable types vs non-nullable types, and in the best case scenario nullable types are 2x slower, but often far worse. The data type most often used is double, and currently the chosen alternative to null is double.NaN. However I understand this is not the exact intended usage for the NaN value,

Coding practices for C# Nullable type [closed]

本小妞迷上赌 提交于 2019-12-03 05:47:07
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . I have never used nullable types in my C# code. Now I have decided to change my coding practice by introducing nullable types in my code. What are the major changes in the coding practices should be made while making a transition from normal datatypes to nullable data-types

Whats the use of Nullable.GetUnderlyingType, if typeof(int?) is an Int32?

痴心易碎 提交于 2019-12-03 05:44:38
why is typeof int? an Int32 int? x = 1; Console.WriteLine(x.GetType().Name); If it is okay then what's the use of Nullable.GetUnderlyingType ? Calling GetType() boxes your variable. The CLR has a special rule that Nullable<T> gets boxed to T . So x.GetType will return Int32 instead of Nullable<Int32> . int? x = 1; x.GetType() //Int32 typeof(int?) //Nullable<Int32> Since a Nullable containing null will be boxed to null the following will throw an exception: int? x = null; x.GetType() //throws NullReferenceException To quote MSDN on Boxing Nullable Types : Objects based on nullable types are

DataSet does not support System.Nullable<> in Export

爱⌒轻易说出口 提交于 2019-12-03 04:30:22
问题 I was trying to generate a Report using Export to Excell, PDF, TextFile. Well I am doing this in MVC. I have a class which I named SPBatch (which is the exact name of my Stored Procedure in my SQL) and it contains the following: public string BatchNo { get; set; } public string ProviderName { get; set; } public Nullable<System.Int32> NoOfClaims { get; set; } public Nullable<System.Int32> TotalNoOfClaims { get; set; } public Nullable<System.Decimal> TotalBilled { get; set; } public Nullable

Is Nullable<int> a “Predefined value type” - Or how does Equals() and == work here?

时间秒杀一切 提交于 2019-12-03 04:24:51
For my own implementation of an Equals() method, I want to check a bunch of internal fields. I do it like this: ... _myNullableInt == obj._myNullableInt && _myString == obj._myString && ... I would assume, that this compares the values, including null, for equality not the object address (as a reference euqality compare operation would) because: It is said so for "predefined value types" in this MSDN doc here . I assume Nullable<int> is such a "predefined value type" because of it is in the System Namespace according to this MSDN doc . Am I right to assume that the VALUES are compared here?

Is there an option to make Entity Framework revert empty strings to null?

我与影子孤独终老i 提交于 2019-12-03 03:21:41
I am using an ADO.NET Entity-Framework ObjectContext to access my data store. I want the if values are set with empty strings, they should automatically become null. Sterling Nichols If your using Entity Framework 4, you can use T4 templates to accomplish this. Just place this in the getter of each string property in your .tt template file, and it will replace empty strings with null and automatically trim strings. No need to use reflection. <#+ if (primitiveProperty.TypeUsage.ToString().Split('.').Last() == "String") { #> if (value == "") value = null; else value = value.Trim(); <#+ } #> I