null

C# Nested null checks in if statements

I have a question on programming style and C# language design in general, I'd love to know if there is a better way to do what I'm doing. If you have a complex data object, with properties that can be null but you want to check or operate on data if it is there, you cannot write a line like so if(Myobject.MyNestedObject != null || Myob...

The || (or) Operator in Linq with C#

Hi, I'm using linq to filter a selection of MessageItems. The method I've written accepts a bunch of parameters that might be null. If they are null, the critea for the file should be ignored. If it is not null, use it to filter the results. It's my understanding that when doing an || operation is C#, if the first expression is true, t...

What is the correct way to represent null XML elements?

I have seen null elements represented in several ways: The element is present with xsi:nil="true": <book> <title>Beowulf</title> <author xsi:nil="true"/> </book> The element is present, but represented as an empty element (which I believe is wrong since 'empty' and null are semantically different): <book> <title>Beowu...

Is null harmful? [Duplicate]

Duplicate: http://stackoverflow.com/questions/163434/are-nulls-in-a-relational-database-okay I dodged a heated debate concerning nulls in the database today. My opinion is that null is an excellent indicator of unspecified values. Every one else in the team, that has an opinion, thinks zero and empty strings are the way to go. Ar...

MembershipUser constructor expects dateTime fields that might be null

The MemberShipUser constructor expects dateTime fields like lastLoginDate, which may be null in the data store. However, when I retrieve data from the store and pass null in for the parameter, I get an error that it cannot be null. How can I work around this? ...

Why nullable types will not be equal in this case?

Surprisingly the code bellow will not succeed. int? n1 = null; int? n2 = null; Assert.IsTrue(n1 <= n2); // Fails here Do you know why? ...

C#: How to Implement and use a NotNull and CanBeNull attribute

I want to let programmers and myself know that a method does not want null and if you do send null to it anyways, the result will not be pretty. There is a NotNullAttribute and a CanBeNullAttribute in Lokad Shared Libraries, in the Lokad.Quality namespace. But how does that work? I looked at the source-code of those two attributes, an...

Null object in javascript

Why null is considered an object in javascript? Is checking if ( object == null ) do something same as if ( !object ) do something And also What is the difference between null and undefined?? ...

How to write a null safe compare "<=>" in pure SQL?

In Mysql there is a compare operator that is a null safe: <=>. I use this in my Java program when creating prepared statements like this: String routerAddress = getSomeValue(); String sql = "SELECT * FROM ROUTERS WHERE ROUTER_ADDRESS <=> ? "; PreparedStatement stmt = connection.prepareStatement(sql); stmt.setString(1, routerAddress); ...

C: Reasons why a passed parameter is NULL after function call to a different module

Hello, I've a curious behavior in a C program. I pass a few arguments to a function with the following signature in a file called foo.c: foo (char *first, size_t a, size_t b, size_t c, char *last); Now, when I call this function from another C file that includes foo.h, e.g. with: foo("first value", 1, 2, 3, "last value"); in foo f...

Is It Necessary to Set Pointers to nil in Objective-C After release?

Title says it all I guess. Is there anything wrong with doing something like NSString * string = [ [ NSString alloc ] init ]; ... [ string release ]; or is there any value (other than best practice) in also adding string = nil; ? ...

sql server 2005 :how to put not null constraint on a column depending upon value in other column?

in a table two of columns are billable(bit),billabledate(datetime).i want billable date to be not null if billable is not null. ...

Why shouldn't I always use nullable types in C#.

I've been searching for some good guidance on this since the concept was introduced in .net 2.0. Why would I ever want to use non-nullable data types in c#? (A better question is why wouldn't I choose nullable types by default, and only use non-nullable types when that explicitly makes sense.) Is there a 'significant' performance hit ...

A /dev/null equivilent for DISPLAY when the display is just noise.

I'm running a java app which creates a visual display of some of the things it is doing, while it is doing it. However, I'm want to run this in a script that won't have a display to attach to. In the current environment, there isn't even a DISPLAY environment variable set. I tried to simply set my DISPLAY to :0.0. But that doesn't exist....

C# Initialization Confusion!

int? test; try { test = (int?) Int32.Parse ("7"); } catch {} if (test == null) Console.WriteLine("test is null!"); else Console.WriteLine("test = {0}", test); I am have some code that does something VERY similar to this, same idea really... Creating a variable, trying to initialize it, then test to see if the initializa...

DateTime nullable exception as a parameter

I have a Search Form that can search by a few different fields. The problem field is birthDate. On the form it is a string. In the SQL 2005 db it is a DateTime that can be null. The code below is sequential as far as declaring the variable on the form and then setting it. Then the call to the BLL and then the call to the DAL. On ...

Do we really need NULL?

Is there an actual need for NULL or not? In most of the OO languages i have programmed in there has always been a way to set a variable to a NULL value which lead to all sorts of funny problems. What are your thoughts? ...

MySql NOT NULL Constraint doesnot work

I am trying to implement NOT NULL constraint in the customer table which is created as: CREATE TABLE CUSTOMER( cust_id INT(5) NOT NULL AUTO_INCREMENT, PRIMARY KEY(cust_id), first_name VARCHAR(25) NOT NULL, last_name VARCHAR(25) NOT NULL, email VARCHAR(25) NOT NULL, password VARCHAR(25) NOT NULL, gende...

In C#, what happens when you call an extension method on a null object?

Does the method get called with a null value or does it give a null reference exception? MyObject myObject = null; myObject.MyExtensionMethod(); // <-- is this a null reference exception? If this is the case I will never need to check my 'this' parameter for null? ...

Count distinct and Null value is eliminated by an aggregate

I'm using SQL Server 2005. With the query below (simplified from my real query): select a,count(distinct b),sum(a) from (select 1 a,1 b union all select 2,2 union all select 2,null union all select 3,3 union all select 3,null union all select 3,null) a group by a Is there any way to do a count distinct without getting "Warning: Null...