nullable

Why is Nullable<T> considered a struct and not a class?

心已入冬 提交于 2019-12-08 17:13:50
问题 I'm trying to define a generic class that takes any type that can be set to null: public abstract class BundledValue_Classes<T> where T : class { private Tuple<T, object> _bundle= new Tuple<T, object>(); public T Value { get { return _bundle == null ? null : _bundle.Item1; } set { _bundle = new Tuple<T, object>(value, obj); } } //... This works fine. I also want to create a derived class that can take any primitive type (int, double, etc), and simply resolve that into the same as the above

Varchar columns: Nullable or not

£可爱£侵袭症+ 提交于 2019-12-08 15:31:52
问题 The database development standards in our organization state the varchar fields should not allow null values. They should have a default value of an empty string (""). I know this makes querying and concatenation easier, but today, one of my coworkers questioned me about why that standard only existed for varchar types an not other datatypes (int, datetime, etc). I would like to know if others consider this to be a valid, defensible standard, or if varchar should be treated the same as fields

MVC map to nullable bool in model

社会主义新天地 提交于 2019-12-08 15:04:50
问题 With a view model containing the field: public bool? IsDefault { get; set; } I get an error when trying to map in the view: <%= Html.CheckBoxFor(model => model.IsDefault) %> Cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?) I've tried casting, and using .Value and neither worked. Note the behaviour I would like is that submitting the form should set IsDefault in the model to true or false. A value of null simply means that the model has

Make An Integer Null

▼魔方 西西 提交于 2019-12-08 14:50:51
问题 I have an update function that updates an sql server db table through a dataset. One of the fields in the table is an integer and accepts null values. So when I am populating the update function I need a way to enter a null in when the function wants an integer. I tried to do it this way but _intDLocation = "" throws an exception Dim _dLocation As String = udDefaultLocationTextEdit.Text Dim _intDLocation As Integer If _dLocation <> "" Then _intDLocation = Integer.Parse

Cannot implicitly convert type 'long' to “int?”?

梦想与她 提交于 2019-12-08 10:25:14
问题 It a very simple question - convert a type long variable to a Nullable int type (int?). (see example below- not the actual code) int? y = 100; long x = long.MaxValue; y = x; I am getting compile time error. "Cannot implicitly convert type 'long' to 'int?'. An explicit conversion exists (are you missing a cast?). I do have the fix ( see below the solution section), My curiosity in posting the question is of the 3 solutions which one is recommended? Solution y = Convert.ToInt32(x); y = (int)x;

Is there a good Eclipse plugin for checking @Nonnull and @Nullable annotations?

百般思念 提交于 2019-12-07 09:58:42
问题 The checking of the @Nonnull and @Nullable annotations in Eclipse is an early beta. The largest problem is that there it no knowing over the null behavior of the Java API. Are there any other plugins that are better currently? 回答1: It's now integrated in Eclipse Kepler. 回答2: I have found that FindBugs works well and is easy to use. FindBugs Plugin 回答3: Get Eclipse SDK 3.7(or Indigo) Enter this update URL: http://download.eclipse.org/objectteams/updates/contrib Select and install : JDT Null

Cast a null into something?

六月ゝ 毕业季﹏ 提交于 2019-12-07 06:09:00
问题 I had this interesting discussion today with a colleague. We were debating two pieces of code in C#. Code Snippet 1: if(!reader.IsDBNull(2)) { long? variable1 = reader.GetInt64(2) } Code Snippet 2: long variable1 = reader.IsDBNull(2) ? (long?) null : reader.GetInt64(2) Question is: is it a good practice to cast null into a nullable long? Or would you rather use the traditional if statement to avoid casting null to nullable long. 回答1: The expressions (type?)null , default(type?) and new

The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable<T>'

会有一股神秘感。 提交于 2019-12-07 05:23:43
问题 public virtual int Fill(DataSetservices.Jobs_detailsDataTable dataTable, global::System.Nullable<global::System.String> fromdate, global::System.Nullable<global::System.DateTime> todate) I wrote above code in dataset.xsd in C#, but it is throwing an error: Error 1 The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable' Suggest me how to use string because i want to use string and nothing else 回答1: string is

Can't Deserialize a Nullable KeyValuePair from JSON with ASP.NET AJAX

偶尔善良 提交于 2019-12-07 04:02:56
问题 The following class does not deserialize (but does serialize) using System.Web.Script.Serialization.JavaScriptSerializer . public class foo { public KeyValuePair<string, string>? bar {get;set;} } The attempt to deserialize results in a System.NullReferenceException when System.Web.Script.Serialization.ObjectConverter.ConvertDictionaryToObject reaches the bar property. (Note, that is a surmise based on the stack trace.) Changing the property type to KeyValuePair<string,string> fixes the

In C#, what is the `?` in the type `DateTime?` [duplicate]

让人想犯罪 __ 提交于 2019-12-07 03:35:49
问题 This question already has answers here : What does “DateTime?” mean in C#? (6 answers) Closed 6 years ago . I just ran across some code while working with System.DirectoryServices.AccountManagement public DateTime? LastLogon { get; } What is the ? after the DateTime for. I found a reference for the ?? Operator (C# Reference), but it's not the same thing. (280Z28: Here is the correct link for Using Nullable Types.) 回答1: The ? makes it a nullable type (it's shorthand for the Nullable<T>