Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Difference between .HasValue and empty string

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
1088 Views, 4 Replies

Difference between .HasValue and empty string

Hi everyone, what is the difference between !el.LookupParameter("Company").HasValue and el.LookupParameter("Company").ToString() != "" ? 

 

foreach (Element el in _AllElements)
{
if (!el.LookupParameter("Company").HasValue || el.LookupParameter("Company").ToString() != "" )
{
//code1
}
}

 

Why if I have only !el.LookupParameter("Company").HasValue the debugger just skips the execution of code1 but if I have both conditions that's when it actually finds unfilled parameter "Company" and executes everything inside of if statement ?

Labels (4)
4 REPLIES 4
Message 2 of 5
sahin.ikbal
in reply to: Anonymous

It works very similar to normal string of C#.

Difference between
String s=null;

and 

String s= "";

 

Message 3 of 5
Anonymous
in reply to: sahin.ikbal

@sahin.ikbal you are comparing  "String s=null" and "!el.LookupParameter("Company").HasValue" ?

in that case the question now is what is the difference between

e.LookupParameter("Company") != null

and

!el.LookupParameter("Company").HasValue

Thank you!

Message 4 of 5
sahin.ikbal
in reply to: Anonymous

e.LookupParameter("Company") != null

Here the whole parameter is null, this will only come once there is no such parameter.

But if the parameter value type is something nullable than that null is found by HasValue.

 

 

Message 5 of 5
RPTHOMAS108
in reply to: Anonymous

Parameter.HasValue should be renamed. It appears to indicate a state that only exists prior to a parameter being assigned it's first value i.e. false if never used (would like to know if there are any instances otherwise). I don't know if it was meant to work that way but it is the way it appears to work.

 

Probably it comes from exposing some unmanaged idea that we need to check pointer actually refers to something (even that something being nothing) i.e. memory allocated before using it.

 

So not of much use as far as I can tell and a bit dangerously named (depending on your personal philosophy of the meaning of nothing).

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community