I have a simple method that returns a Nullable Int32 from a DataReader rather than the built in GetInt32.
I am calling this method many many times and have one situation where any time I can shave off of it would be beneficial.
Can anyone suggest any alternative and faster ways of getting a nullable Int32 out of the DataReader?
privat...
I've just started writing on a component where I found it might be useful to declare some of the properties nullable, instead of letting them resort to default values. However, I realized that I've never before used the non-nullable-type? syntax or the Nullable<T> type before, so there are probably some gotchas that'll soon jump out and ...
I'm trying to create a simple Clamp (so that I can bound the values of anything comparable ... mostly for number types such as int, double, etc.)
The problem is if I do the following I get an error, but according to MSDN IComparable's CompareTo is supposed to be able to handle null values.
Quote: "By definition, any object compares grea...
Strongly-typed DataTables support "nullable" field types, except that the designer will not allow you change the setting to "allow nulls" for any value type fields. (ie: String types allow nullable, but int's do not).
The workaround is to call IsMyFieldNull() any time you want to get Myfield. If you access MyField when it does contain ...
Hi,
I was looking at this article and am struggling to follow the VB.NET example that explains lifted operators. There doesn't seem to be an equivalent C# example or tutorial. I don't have much experience with operator overloading in general, so trying to come to terms with the VB.NET equivalent whilst reading up on nullable types proba...
I wanted to assign null value to DateTime type in c#, so I used:
public DateTime? LockTime;
When LockTime is not assigned LockTime.Value contains null by default.
I want to be able to change LockTime.Value to null after it has been assigned other value.
...
public partial class L2SEntity {
public void Scale(double d) {
if (this.Amount.HasValue)
this.Amount.Value *= d;
}
}
Results in the following error:
Error 2 Property or indexer 'System.Nullable<double>.Value' cannot be assigned to -- it is read only
How do I change the Amount's (type of double?) value...
Taken from one of my previous questions.
Table is telling on which item (post , photo or reply) the comment is taking place on.
commentid ---- postid ----- photoid-----replyid
-----------------------------------------------
1 22 NULL NULL
2 NULL 56 NULL
3 23...
Hi,
Is there a way in fluorine to force a nullable double to be passed to flex as NaN? (and vice versa)
By default these values are passed as null, but a Number in actionscript is not nullable, so it is converted to 0 by default.
I need server side nullable doubles to be NaN in flex, and NaN values from flex to be nullable doubles on t...
Given the following ASP.NET code:
[System.Web.Script.Services.ScriptService]
public class Quotes : System.Web.Services.WebService
{
[WebMethod]
public void Calculate(int param1, int? param2)
{
etc.. How can I pass a null value to param2? If I don't pass the parameter at all, or I pass undefined, my error handler fires wi...
So, a couple of questions, actually:
An int (Int32) is specified to be (obviously) 32 bits. What about an int? (Nullable<int>)? My gut tells me that it would be 32 bits for the integer plus 8 more bits for the boolean, but perhaps the implementation is more intricate than that.
I would have answered my own question using sizeof(int?); ...
Hi!
Basically, Nullable<T> is a structure, which explains things like calling .HasValue will never throw a NullReferenceException. I was wondering why - given a nullable which does not have a value - comparisons to null are always true, even when using Object.ReferenceEquals, which I thought would return false because it is a structure....
Enums are generally used to define the state of a particular property of a class, say in an object model of some sort. For some of these properties, the state 'this property is not set' is valid.
In these situations, should I use a zero None enum value, or make the property type nullable?
public MyEnum Property { get; set; }
public en...
I couldn't find best solution when DateTime value is NULL.
I use this techinque When binding;
_ACTIVATION_DATE = dt.Rows[0]["ACTIVATION_DATE"] == DBNull.Value ? new DateTime(1970, 12, 30) : (DateTime?)dt.Rows[0]["ACTIVATION_DATE"];
When Inserting;
public void Insert()
{
string ad="";
string dd="";
if (ACTIVATION_DATE ==...
How can i implement a "optional" parameter to a function such that when endMarker is not given, i will use the value from a required parameter startMarker? i currently use a nullable type and check if endMarker is null i set it to startMarker
protected void wrapText(string startMarker, string? endMarker = null) {
if (endMarker == n...
I'm trying to find the right thing to do with a non-null validation on a nullable boolean. I also want to be able to do the same thing with some other fields, including strings, ints, etc., so I want to use generics for the method. Here's an example of the kind of thing which can happen.
bool? myValue = null;
bool valid = ValidateNotNul...
I have:
Dim nVar1 As Long?
Dim nVar2 As Long?
Dim nVarSum As Long?
nVar1 = Nothing
nVar2 = 5
nVarSum = nVar1 + nVar2
I would prefer the result to end with nVarSum being 5, instead of Nothing.
I understand if you add something to an unknown value, you will end up with "somthing + unknown" or
x+5 will always equal "x+5" not "5" be...
I'm trying this (and all PoST var are treated before user send it, no SQL Injection worries):
$stmt = $con->prepare($sql);
$stmt->bindParam(":1", $this->getPes_cdpessoa());
$stmt->bindParam(":2", $this->getPdf_nupessoa_def());
When any of those vars are NULL, PDO cries and don't let execute my statement, and on my Table, i DO allow th...
This has me pretty stumped. Maybe I'm too tired right now.
Rectangle rectangle = new Rectangle(0, 0, image.Width, image.Height);
Rectangle cropArea = inputArea == null ? rectangle : inputArea.Value;
if (inputArea == null)
cropArea = rectangle;
inputArea is a nullable Rectangle, which in my particular case is null....
Apparently you can't have a Nullable<Rectangle> in Silverlight. I'd like to know the technical reasons why not and how many objects this may apply to?
Today I accidentally started a small comment flamewar after stating that the "Rectangle" type was not a Nullable type. That is you can't have a "Nullable<Rectangle>" or a "Rectangle?"
My...