null-check

Null or empty check for a string variable

此生再无相见时 提交于 2019-12-03 22:21:17
if((isnull(@value,''))='') I want to know whether the above piece of code works in checking if the variable is null or empty. Yes, that code does exactly that. You can also use: if (@value is null or @value = '') Edit: With the added information that @value is an int value, you need instead: if (@value is null) An int value can never contain the value '' . AnasChavadi Use This way is Better if LEN(ISNULL(@Value,''))=0 This check the field is empty or NULL Yes, you could also use COALESCE(@value,'')='' which is based on the ANSI SQL standard: SELECT CASE WHEN COALESCE(@value,'')='' THEN 'Yes,

C#: How to perform a null-check on a dynamic object

喜你入骨 提交于 2019-12-03 19:11:33
问题 How do I perform a null-check on a dynamic object? Pseudo code: public void Main() { dynamic dynamicObject = 33; if(true) { // Arbitrary logic dynamicObject = null; } Method(dynamicObject); } public void Method(dynamic param) { // TODO: check if the content of 'param' is equal to null } 回答1: Are you worried about the possibility the dynamic object will have a custom equality operator that will change the way the null is interpreted? If so just use Object.ReferenceEquals if (Object

difference between null != something and something != null

≡放荡痞女 提交于 2019-12-02 07:11:19
问题 Is there a difference between null != something and something != null in Java. And if there is a difference then which one should I use and why?? 回答1: its probably comming from the so-called joda-conditions where you write "bla" == myVariable instead of myVariable == "bla" because it could happen to accidentially write myVariable = "bla" which returns "bla" in some languages but also assign "bla" to myVariable 回答2: There's no difference between null != something and something != null . You

difference between null != something and something != null

社会主义新天地 提交于 2019-12-02 06:56:35
Is there a difference between null != something and something != null in Java. And if there is a difference then which one should I use and why?? its probably comming from the so-called joda-conditions where you write "bla" == myVariable instead of myVariable == "bla" because it could happen to accidentially write myVariable = "bla" which returns "bla" in some languages but also assign "bla" to myVariable There's no difference between null != something and something != null . You must be thinking about the person.getName().equals("john") and the "john".equals(person.getName()) difference: the

C# null check chain in method call

五迷三道 提交于 2019-12-01 22:39:30
I suppose method call chain below. void DoSomething() { ObjectA a = CreateA(); if (a != null) { a.Foo(); } } ObjectA CreateA() { ObjectB b = CreateB(); if (b != null) { ObjectA a = b.ToA(); return a; } return null; } If method call depth get deeper, null checking will be more overlapped. Is there any good solution for this? Modified I changed example code. It can't solve my problem that change CreateA to constructor. The problem is only unnecessary null check chaining overlapping. void SetImage() { UISprite image = GetSprite(); if (image != null) { image.spriteName = "hat"; } } UISprite

Null coalescing operator in React JS/ Typescript [duplicate]

拜拜、爱过 提交于 2019-12-01 16:53:47
This question already has an answer here: Typescript the safe navigation operator ( ?. ) or (!.) and null property paths 5 answers Replacement of Elvis Operator of Angular2 in Typescript 2 answers We have the Null coalescing operator in .NET and we can use as below string postal_code = address?.postal_code; Same thing can we do in React JS? What i found like we can do with && operator in address.ts file string postal_code = address && address.postal_code; what i need like .net feature is possible in typescript with react JS, is that possible ? something like: string postal_code = address?

Null coalescing operator in React JS/ Typescript [duplicate]

白昼怎懂夜的黑 提交于 2019-12-01 16:00:44
问题 This question already has answers here : Typescript the safe navigation operator ( ?. ) or (!.) and null property paths (6 answers) Replacement of Elvis Operator of Angular2 in Typescript (2 answers) Closed last year . We have the Null coalescing operator in .NET and we can use as below string postal_code = address?.postal_code; Same thing can we do in React JS? What i found like we can do with && operator in address.ts file string postal_code = address && address.postal_code; what i need

Performance hit of checking for null

放肆的年华 提交于 2019-12-01 12:05:45
Can anyone tell me what the performance cost is of checking if an object or property of an object is null in c#? I am working on an ASP.NET MVC application that the null checking is being done in the Model and then done again in the view. I feel that this is excessive but if there is no real performance hit then I don't see the harm in doing things this way. I don't think its measurable if you're doing it just once while rendering and once while initializing the model. It would have an impact if it were inside a computation-intensive loop though. Things like querying the database, read/write

Performance hit of checking for null

匆匆过客 提交于 2019-12-01 10:58:34
问题 Can anyone tell me what the performance cost is of checking if an object or property of an object is null in c#? I am working on an ASP.NET MVC application that the null checking is being done in the Model and then done again in the view. I feel that this is excessive but if there is no real performance hit then I don't see the harm in doing things this way. 回答1: I don't think its measurable if you're doing it just once while rendering and once while initializing the model. It would have an

C#: How to perform a null-check on a dynamic object

别说谁变了你拦得住时间么 提交于 2019-11-30 05:58:31
How do I perform a null-check on a dynamic object? Pseudo code: public void Main() { dynamic dynamicObject = 33; if(true) { // Arbitrary logic dynamicObject = null; } Method(dynamicObject); } public void Method(dynamic param) { // TODO: check if the content of 'param' is equal to null } JaredPar Are you worried about the possibility the dynamic object will have a custom equality operator that will change the way the null is interpreted? If so just use Object.ReferenceEquals if (Object.ReferenceEquals(null, param)) { ....... } You can always just make the param of type object, that's what the