Using c#, How can I take benefit of using nullable valuetypes when I have a variable of object type? -
Using C #, I can take advantage of a variable type of object when using null value values ?
For example, I have a method that takes 4 arguments:
public int update (int32 serial, object delivery date, object quantity, object changes Time) {.... .... ....}
As you can guess, this method contains a new record in the table Table (Table 1) There are 4 columns: Serial Int, Delivery That Datetime Free, Quantity Float Faucet and Softtime SmallNet Empty
Now, May Received concession is: I can take advantage of how to use the tap value-type and I do can change Dettaim like my desirable types I object?
Thank you
Why are your criteria of type object in the first place? Why is it not:
public int update (int serial, datetime? Delivery date, double? Quantity, less? Change time)
(note That decimals
can be a better option than double
.)
If you can possibly change your signature, then you probably know how to get it.
Otherwise, what are you really asking in your question? If you can change not parameters, but type arguments DateTime
(or null), double
(or null) and Small
(or null) then you can put them on your faucet equivalent. Non-empty values for that type of zero value, and non-empty values, will be unboxed null
:
object x = 10; Int? Y = (int?) X; // y = zero-zero value 10 x = faucet; Y = (int?) X; // y tapable & lt; Int & gt; Edit
Type: You have a text box for shift time, three options Are: it is full but inappropriate (eg "foo"), it is empty, or it is valid. You want to do something like this:
small? ShiftTime = Faucet; String User Input = shiftTimeInput.Text; If (userInput.Length> gt; 0) // user has * entered * some * in small value; If (short.TryParse (user input, out value)) {shiftTime = value; } Else {// Invalid to handle input // whatever you want} // Now shiftTime is either empty if the user has left it blank, or call the update method that is passing in the correct value // shiftTime.
Comments
Post a Comment