|
Consider the following statements:
int? v1 = null; int? v2 = 5 * v1;
What is the value of v2 ? ( null or empty string?)
How can I prevent the compiler to mark it as invalid operation? Do I need to follow custom exception handling?
Answer Snippets (Read the full thread at stackoverflow):
C# Language Specification 3.0 (Section §7.2.7: Lifted operators) For the binary ? modifier to each operand and result... .
int? v2 = v1.HasValue ? 5 * v1.Value : null;
or
int? v2 = nullIt's null .
Has a value prior to using it.
|
|
What is the best way to convert an int or null to boolean value in an SQL query, such that:
Any non-null value is TRUE in the results Any null value is FALSE in the results
Started by Thomas Bratt on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
When:
select (column_name is not null) as result from table_name;
Returns....
Isnull(column - column + 1, 0) != 0
SELECT CASE WHEN thevalue IS NULL THEN 0 ELSE 1 END AS newVal to be WHEN thevalue IS NULL THEN 0
No need to use case...
|
|
How can i get 0 as integer value from (int)null .
EDIT 1: I want to create a function that will return me default values for null representation in their respective datatypes.
EDIT 2: How can i work in this scenario for using default .
(int)Value
Where...
Started by Shantanu Gupta on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
What the default value of any data type:
int x = default(int); // == 0 string y = default(string); // == null....
You can cast it to an int? though.
You can't cast a null to an int, as an int is a value type.
|
Ask your Facebook Friends
|
Possible Duplicate:
Nullable types and the ternary operator. Why won’t this work?
Why doesn't this work? Seems like valid code. Can anyone help?
string cert = ddCovCert.SelectedValue; int? x = (string.IsNullOrEmpty(cert)) ? null: int.Parse(cert); Display...
Started by Kettenbach on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
I usually just cast the null to (int?)
int? x = (string.IsNullOrEmpty(cert)) ? (int?)null.
int? x = string.IsNullOrEmpty(cert) ? (int?)null : int.Parse(cert);
I've come across the same thing ...
|
|
Can an int be null in Java?
For example:
int data = check(Node root); if ( data == null ) { // do something } else { // do something }
My goal is to write a function which returns an int . Said int is stored in the height of a node, and if the node is...
Answer Snippets (Read the full thread at stackoverflow):
Depending on your check method, you never be null....
In Java, int is a primitive type and it is not considered Integer represents an int value, but it can hold a null value.
Args[]) { int i = null; }
Try to compile.
|
|
Say I have following the following snippet (context narrowed down to limit scope of question)
int? nullableId = GetNonNullableInts().FirstOrDefault();
Because GetNonNullableInts() returns ints, the FirstOrDefault will default to 0.
Is there a way to make...
Started by boris callens on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
So you'll need to....
int? nullableId = GetNonNullableInts().Cast<int?>().FirstOrDefault();
FirstOrDefault depends on T from IEnumerable<T> to know what type to return, that's why you're receiving int instead int? .
|
|
I have a linq query function like (simplified):
public IList<Document> ListDocuments(int? parentID) { return ( from doc in dbContext.Documents where doc.ParentID == parentID select new Document { ID = doc.ID, ParentID = doc.ParentID, Name = doc....
Started by Kelsey on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
When you explicitly test against null , the generated SQL will use the IS NULL operator, but when you're using a parameter it will use the standard....
Literal null values are handled differently than parameters which could be null.
|
|
Hi,
I'm looking for a point in the right direction to solving this problem.
I am being passed an object from the ui.
One of the values is for a foreign key (an int which allows nulls). The value being sent is -1 which signifies that the value has not ...
Answer Snippets (Read the full thread at stackoverflow):
If (valueReceived == -1) entity.NullableValue = null....
Public virtual int? ForeignKeyFieldId { get; set; }
Finally, I'd convert your -1 to null as soon int Id {get; private set;} public int? NullableValue {get;set;} } ...
|
|
I was looking at this, http://en.wikipedia.org/wiki/Strategy_pattern and I understand the concept of the strategy pattern, but could someone explain the C# example a bit.
I dont really get the how and why of the definition of 'Strategy' in the Context...
Started by RobbieFowler on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
A Func<T, T1, T2>.
Arg2) => return new TResult();
Func<int, int, int> is a func that take two int arguments and returns an int - the last type in a Func definition is the return type.
|
|
In case of integer overflows what is the result of (unsigned int) * (int) ? unsigned or int?
I was auditing the following function, and suddenly I came out with that question. In the below function, it is vulnerable at line 17.
1. // Create a character...
Started by yinyueyouge on
, 12 posts
by 12 people.
Answer Snippets (Read the full thread at stackoverflow):
In any case, i*w is guaranteed the product of two ... .
Return (NULL);
On int , unsigned int mixed operations, int is elevated to unsigned intWhy not just declare i as unsigned int? Then the problem goes away.
; 4096) 10.
|