using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace NullableDataTypes
{
public class Program
{
//Like DataBase ISNULL() Function the "??" operator works
//e.g. ISNULL(null,1) o/p will be 1
//Similarly val3= val1 ?? val2;
//val3 will be val2 if al1=null
public static Object IsNull( object objReplace, object objSearch)
{
Object _newVal = 0;
if (objSearch is string)
{
string val = objReplace as string;
_newVal = val ?? objSearch as string;
}
else if (objSearch is int)
{
int? val = objReplace as int?;
_newVal = val ?? objSearch as int?;
return _newVal;
}
else if (objSearch is double)
{
double? val = objReplace as double?;
_newVal = val ?? objSearch as double?;
return _newVal;
}
else if (objSearch is float)
{
float? val = objReplace as float?;
_newVal = val ?? objSearch as float?;
return _newVal;
}
else if (objSearch is decimal)
{
decimal? val = objReplace as decimal?;
_newVal = val ?? objSearch as decimal?;
return _newVal;
}
else if (objSearch is long)
{
long? val = objReplace as long?;
_newVal = val ?? objSearch as long?;
return _newVal;
}
else if (objSearch is bool)
{
bool? val = objReplace as bool?;
_newVal = val ?? objSearch as bool?;
return _newVal;
}
else
{
_newVal = -1;
return _newVal;
}
return _newVal;
}
static void Main(string[] args)
{
/**
* We are storing the returned value in Annoynoumus Type variable
*/
var b = IsNull(null, "Bimlesh");
Console.WriteLine("{0}",b);
Console.Read();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace NullableDataTypes
{
public class Program
{
//Like DataBase ISNULL() Function the "??" operator works
//e.g. ISNULL(null,1) o/p will be 1
//Similarly val3= val1 ?? val2;
//val3 will be val2 if al1=null
public static Object IsNull( object objReplace, object objSearch)
{
Object _newVal = 0;
if (objSearch is string)
{
string val = objReplace as string;
_newVal = val ?? objSearch as string;
}
else if (objSearch is int)
{
int? val = objReplace as int?;
_newVal = val ?? objSearch as int?;
return _newVal;
}
else if (objSearch is double)
{
double? val = objReplace as double?;
_newVal = val ?? objSearch as double?;
return _newVal;
}
else if (objSearch is float)
{
float? val = objReplace as float?;
_newVal = val ?? objSearch as float?;
return _newVal;
}
else if (objSearch is decimal)
{
decimal? val = objReplace as decimal?;
_newVal = val ?? objSearch as decimal?;
return _newVal;
}
else if (objSearch is long)
{
long? val = objReplace as long?;
_newVal = val ?? objSearch as long?;
return _newVal;
}
else if (objSearch is bool)
{
bool? val = objReplace as bool?;
_newVal = val ?? objSearch as bool?;
return _newVal;
}
else
{
_newVal = -1;
return _newVal;
}
return _newVal;
}
static void Main(string[] args)
{
/**
* We are storing the returned value in Annoynoumus Type variable
*/
var b = IsNull(null, "Bimlesh");
Console.WriteLine("{0}",b);
Console.Read();
}
}
}