Say I have a method that takes an int as a string and returns the int if the parse succeeds or a null value otherwise.
int? ParseValue(string intAsString)
{
int i;
if (int.TryParse(intAsString, out i))
return i;
return null;
}
How can this method be re-written so that it works not only w...
Hello, please take a look at the following line
<TextBox Text="{Binding Price}"/>
This Price property from above is a Decimal? (Nullable decimal).
I want that if user deletes the content of the textbox (i.e. enters empty string, it should automatcally update source with null (Nothing in VB).
Any ideas on how I can do it 'Xamly'?
...
There is paradox in the exception description:
Nullable object must have a value (?!)
This is the problem:
I have a DateTimeExtended class,
that has
{
DateTime? MyDataTime;
int? otherdata;
}
and a constructor
DateTimeExtended(DateTimeExtended myNewDT)
{
this.MyDateTime = myNewDT.MyDateTime;
this.otherdata = myNewDT.oth...
My objects often has nullable types properties that used as SQL commands parameters.
I initialize them next way:
public int? Amount
{
get
{
int i;
int? amount = null;
if (Int32.TryParse(Request["amount"], out i))
{
amount = i;
}
return amount;
}
}
command.Parameters.Add("@amount").Value = (object)this.Amount ?? DbNul...
How could I avoid this dictionary (or create it dynamically)?
Dictionary<Type,Type> CorrespondingNullableType = new Dictionary<Type, Type>
{
{typeof(bool), typeof(bool?)},
{typeof(byte), typeof(byte?)},
{typeof(sbyte), typeof(sbyte?)},
{typeof(char), typeof(char?)},
{typeof(decimal), typeof(decimal?)},
{typeof(...
Hi
I am having a problem with subsonic simplerepository.
I have a users class and it has some optional fields.these optional fields are of type string. As soon
as I try to persist my object , if the optional fields are null , an exception is being thrown
I know string is already of type nullable so i cannot do something like nullab...
I have a list of nullable ushorts :
List<ushort?> items = new List<ushort?>();
and I'm trying to get the following to work, but I can't - for some reason.
int GetIndex(ushort value)
{
return ?
}
what I'm trying is :
ushort? x = value;
int idx = items.FindIndex(x);
But I'm getting :
"Best overloaded method has some invalid ...
I've picked up some code from a colleague, and in one of his methods he has a boolean parameter: ByVal showProactiveChases As Boolean?. I had to look up the ? operator yesterday to see that it denotes a Nullable type. My question is, if I change it to: ByVal showProactiveChases As Nullable(Of Boolean), does the meaning remain the same? I...
We are working on exposing an assembly to COM.
Among other things, we frequency use nullable values such as long?, DateTime?, etc. These are generic types and can't be exposed to COM.
What is a good substitute for these data types for COM?
We have tried the following:
//Original CustomerID property in class
public long? CustomerID
{...
If I declare a nullable (either via Nullable or the ? symbol) variable from a value type, does it still respect the rules of value types (i.e. pass by value by default, deallocated when it falls out of scope, not when the garbage collector runs) or does it turn into a reference type since it's actually of type Nullable?
...
I am upgrading an existing application that has implemented a home-brew Constants class in its business and datalayer objects.
I want to replace this with Nullable types and do-away with the constants class, that looks like this, but with all non-nullable data types:
class Constants
{
public static int nullInt
{
get { ...
Have you ever tried to use the Convert.ChangeType() method to convert a value to a Nullable<T> type? Awkwardly, it will throw an InvalidCastException saying "Null object cannot be converted to a value type".
Try running this on your immediate window: ?System.Convert.ChangeType(null, typeof(int?))
For some obscure reason, Nullables are ...
I'm almost sure the answer is simply no, you can't do that.
So I'm working on options for my app.
I've got a decent setup so I have the global options and the local options since you can have different options selected on different tabs.
For the global options I want to represent when an option isn't consistent across all the tabs by r...
Dear Gurus
Today I found a strange problem that is I have a Table With a Nullable Column and I tried to use following Query
SELECT *
Id,
MyNCol,
FROM dbo.[MyTable]
WHERE MyNCol <> 'MyValue'
And Expecting it to return all rows not having 'MyValue' value in Field MyNCol. But its not returning all those Rows Containing N...
I just ran across some code while working with System.DirectoryServices.AccountManagement
public DateTime? LastLogon { get; }
What is the ? after the DateTime for.
I found a reference for the ?? Operator (C# Reference), but it's not the same thing. (280Z28: Here is the correct link for Using Nullable Types.)
...
I am trying to serialize a class several of the data-members are Nullable objects, here is a example
[XmlAttribute("AccountExpirationDate")]
public Nullable<DateTime> AccountExpirationDate
{
get { return userPrincipal.AccountExpirationDate; }
set { userPrincipal.AccountExpirationDate = value; }
}
However at runtime I get the e...
It seems like overkill to set the value of a nullable type and implement iNotifyPropertyChanged. Is there a better way of doing this?
Private _WorkPhone As Long?
Public Property [WorkPhone]() As Long?
Get
Return _WorkPhone
End Get
Set(ByVal value As Long?)
If value.HasValue = F...
please tell me how to implement Nullable Parameter of type string in vb.net
Function:
sub savedetail(byval name as string, byval age as integer)
if name isnot nothing then
some work
end if
end sub
i am calling it like thing
savedetail(nothing,34) //here is giving me format exception
exception :
System.FormatException: Input st...
How can I create a nullable numeric optional parameter in VB.NET?
...
hi
Is there any way to send null to an optional stored procedure parameter via crystal reports8.5 and vb6? I use CRXParamDef.AddCurrentValue method to send stored procedure parameter values.
...