nullable

Nullable Method Arguments in C# [duplicate]

不想你离开。 提交于 2019-12-21 07:14:19
问题 This question already has answers here : Closed 10 years ago . Duplicate Question Passing null arguments to C# methods Can I do this in c# for .Net 2.0? public void myMethod(string astring, int? anint) { //some code in which I may have an int to work with //or I may not... } If not, is there something similar I can do? 回答1: Yes, assuming you added the chevrons deliberately and you really meant: public void myMethod(string astring, int? anint) anint will now have a HasValue property. 回答2:

Assigning null/Nullable to DateTime in Ternary Operation

懵懂的女人 提交于 2019-12-21 07:08:43
问题 I have a statement like DateTime ? dt = (string1 == string2) ? null; (DateTime)(txtbox.Text); which I cannot compile. Reason is : null cannot be assigned to DateTime . So, I have to declare a Nullable<DateTime> nullable variable and replace null with nullable . I do not want to use if -statement and I want to do this in one line. Also, Can I use operator ?? here. 回答1: DateTime? dt = (string1 == string2) ? (DateTime?)null : DateTime.Parse(txtbox.Text); 回答2: you can do it like that: DateTime ?

How does @RequestParam in Spring handle Guava's Optional?

二次信任 提交于 2019-12-20 17:36:48
问题 @RequestMapping(value = "/contact.html", method = RequestMethod.POST) public final ModelAndView contact( @RequestParam(value = "name", required = false) Optional<String> name) { How does Spring's @RequestMapping handle an Optional from Guava library if the parameter value is not required and nothing is sent? Will it be: Set to null Set to Optional.absent() Can Optional.fromNullable(T) be used to accept the request? 回答1: EDIT (October 2015): Spring 4 handles java.util.Optional (from Java 8)

How does @RequestParam in Spring handle Guava's Optional?

本小妞迷上赌 提交于 2019-12-20 17:36:25
问题 @RequestMapping(value = "/contact.html", method = RequestMethod.POST) public final ModelAndView contact( @RequestParam(value = "name", required = false) Optional<String> name) { How does Spring's @RequestMapping handle an Optional from Guava library if the parameter value is not required and nothing is sent? Will it be: Set to null Set to Optional.absent() Can Optional.fromNullable(T) be used to accept the request? 回答1: EDIT (October 2015): Spring 4 handles java.util.Optional (from Java 8)

Can a WCF service contract have a nullable input parameter?

丶灬走出姿态 提交于 2019-12-20 09:58:28
问题 I have a contract defined like this: [OperationContract] [WebGet(UriTemplate = "/GetX?myStr={myStr}&myX={myX}", BodyStyle = WebMessageBodyStyle.Wrapped)] string GetX(string myStr, int? myX); I get an exception: [InvalidOperationException: Operation 'GetX' in contract 'IMyGet' has a query variable named 'myX' of type 'System.Nullable 1[System.Int32]', but type 'System.Nullable 1[System.Int32]' is not convertible by 'QueryStringConverter'. Variables for UriTemplate query values must have types

Equal is not defined between type Nullable<Int32> and Int32

别来无恙 提交于 2019-12-20 04:23:28
问题 I am writing a boring application to manage patients and their clinic history. I used SQLite combined with DbLinq libraries and DbMetal code generation utility. Here are two classes from the genereated code extracted from the underlying database: [Table(Name="main.Patients")] public partial class Patient : System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged { private static System.ComponentModel.PropertyChangingEventArgs emptyChangingEventArgs = new

How does the assignment of the null literal to a System.Nullable<T> type get handled by .Net (C#)?

早过忘川 提交于 2019-12-19 08:59:27
问题 I was wondering if anyone knows how the C# compiler handles the following assignment: int? myInt = null; My assumption is that there is an implicit conversion performed, but I cannot figure out how the null literal assignment is handled. I dissasembled the System.Nullable object and found the implicit operator is overriden to this: public static implicit operator T?(T value) { return new T?(value); } Once called this would try to fire the secondary constructor: public Nullable(T value) { this

Fluent Nhibernate Automap convention for not-null field

允我心安 提交于 2019-12-19 06:31:36
问题 Could some one help, how would I instruct automap to have not-null for a column? public class Paper : Entity { public Paper() { } [DomainSignature] [NotNull, NotEmpty] public virtual string ReferenceNumber { get; set; } [NotNull] public virtual Int32 SessionWeek { get; set; } } But I am getting the following: <column name="SessionWeek"/> I know it can be done using fluent-map. but i would like to know it in auto-mapping way. 回答1: Thank you. Also, for reference properties ReferenceConvention

Fluent Nhibernate Automap convention for not-null field

。_饼干妹妹 提交于 2019-12-19 06:31:17
问题 Could some one help, how would I instruct automap to have not-null for a column? public class Paper : Entity { public Paper() { } [DomainSignature] [NotNull, NotEmpty] public virtual string ReferenceNumber { get; set; } [NotNull] public virtual Int32 SessionWeek { get; set; } } But I am getting the following: <column name="SessionWeek"/> I know it can be done using fluent-map. but i would like to know it in auto-mapping way. 回答1: Thank you. Also, for reference properties ReferenceConvention

Conversion between Nullable types

扶醉桌前 提交于 2019-12-19 06:21:16
问题 Is there a converter in .NET 4.0 that supports conversions between nullable types to shorten instructions like: bool? nullableBool = GetSomething(); byte? nbyte = nullableBool.HasValue ? (byte?)Convert.ToByte(nullableBool.Value) : null; 回答1: Not that I am aware of. You could just write a helper method like this: public Nullable<TTarget> NullableConvert<TSource, TTarget>( Nullable<TSource> source, Func<TSource, TTarget> converter) where TTarget: struct where TSource: struct { return source