Possible Duplicate:
Where in memory are stored nullable types?
A very basic question on Nullable types - where do the nullable values get stored - Heap or Stack?
I would believe it should be stored in Stack as Nullable stack is a struct. How does Null value get stored in a stack?
...
var quantSubset =
from userAns in userAnalysis.AllUserAnswers
join ques in userAnalysis.AllSeenQuestions on userAns.QID equals ques.QID
where (ques.QuestionType == "QT")
select new { QuestionLevel = ques.LevelID, TimeTaken = userAns.TimeTaken, Points = userAns.Points, Us...
I noticed today that if you declare a nullable DateTime object you don't get the same set of functions as you do when you have a standard DateTime object.
For example:
DateTime? nullableDT = DateTime.Now;
DateTime regularDT = DateTime.Now;
in the code above nullableDT cannot use any of the following functions:
ToFileTime
ToFileTim...
I am currently setting the date field to a Datetime.Now which is being done through the SQL query on the database.
I do a
SELECT NVL(mydatefield, sysdate) FROM myView;
This is not the most elegant approach I can think of. The better practice would be to check for a NULL.
I found that the DateTime class does not support the syntax th...
If I have a Type, is there some easy way to tell that it represents a nullable value type using Reflection? Ideally something a little cleaner (and more correct) than:
static bool IsNullable(Type type)
{
return type.IsValueType && type.Name.StartsWith("Nullable");
}
...
in this example code
public Company GetCompanyById(Decimal company_id)
{
IQueryable<Company> cmps = from c in db.Companies
where c.active == true &&
c.company_id == company_id
select c;
return cmps.First();
}
How should I handle...
I am going over some code written by another developer and not sure what 'long?' means:
protected string AccountToLogin(long? id)
{
string loginName = "";
if (id.HasValue)
{
try
{....
...
I'm trying to create a class to use as a field in other objects that can hold a temporary unsaved value until a SaveChanges method is called on the object, so that I can pass the value to a stored proc, which will update any non-null fields with the new value, and leave fields with null as their original values.
I want to be able to do ...
I'm new to nullable types. I like them for adding a value that can mean "no set", but I don't like having to cast them back later on, or having to tack on the .Value.
Here's specifically my scenario in context of a wrapper class that implements one of my repository types:
public DateTime TimeCreated
{
get { return inner.Ti...
The following nullable decimal code fired Overload Method Error:
decimal? t1 = null;
decimal? t2 = null;
decimal? t3 = null;
decimal res = 0;
decimal tt1 = 0;
decimal tt2 = 0;
decimal tt3 = 0;
if (decimal.TryParse(textBox1.Text, out tt1))
t1 = tt1;
if (decimal.TryParse(textBox2.Text, out tt2))
t2 = tt2;
if (decimal.TryParse(tex...
I am working with a 2-D array of nullable booleans bool?[,]. I am trying to write a method that will cycle through its elements 1 at a time starting at the top, and for each index that is null, it will return the index.
Here is what I have so far:
public ITicTacToe.Point Turn(bool player, ITicTacToe.T3Board game)
{
foreach (bool? b...
Hello,
I am currently overriding the setter of a given class with Reflection.Emit.
Everything works fine except when I use it with a nullable property....
Here is the code I use :
ilSetterGen.Emit(OpCodes.Ldarg_0);
ilSetterGen.Emit(OpCodes.Call, baseGetter);
ilSetterGen.Emit(OpCodes.Ldarg_1);
ilSetterGen.Emit(OpCodes.Ceq);
Label retLa...
i have an existing DateTime? object that has a datetime in it. I want to remove the datetime value from it so when you ask "HasValue" it returns false?
...
I have CustomerID declared as
int? CustomerID=null;
I am checking null values while reading DataReader
Id = reader["CustomerId"] is DBNull ? null :Convert.ToInt32(reader["CustomerID"]);
It is throwing
Type of conditional expression cannot be determined because there
is no implicit conversion between '<null>' and 'int'
W...
I want to use the strongly-typed HTML helpers in ASP.NET MVC 2 with a property of my model which is Nullable<T>.
Model
public class TicketFilter {
public bool? IsOpen { get; set; }
public TicketType? Type{ get; set; } // TicketType is an enum
// ... etc ...
}
View (HTML)
<p>Ticket status:
<%: Html.RadioButtonFor(m => m...
Some of the properties in a class generated by EF are nullable, and some arent.
My first instinct was that this should be driven by Nullable property returned by sp_help MyView. But that doesn't seem to be the case.
Some of my types that are returned as Nullable by sp_help get generated as Nullable , while others, get generated as ju...
I saw this thread on Stack Overflow regarding converting between DBNull and nullable types but I am still confused. I have written code like this with some hack code to deal with nullable types for DateTime and ints that I will show below but it'sa mess and I want to use Nullable types:
DataTable dt = ds.Tables[0];
List<RON> list = (f...
The code I want to work:
<Extension()>
Public Function NValue(Of T)(ByVal value As Nullable(Of T), ByVal DefaultValue As T) As T
Return If(value.HasValue, value.Value, DefaultValue)
End Function
So basically what I want it to do, is to give along a default value to a nullable object, and depending on if it's null or not, it will g...
It feels strange to me to be casting null to a type so I wanted to double check that this is the right way to do this:
decimal? d = data.isSpecified ? data.Value : (decimal?)null;
NOTE: I am marking the answer that suggests the method that I personally like the best:
decimal? d = data.isSpecified ? data.Value : default(decimal?)
...