null

null == foo versus foo == null [duplicate]

廉价感情. 提交于 2019-12-19 22:24:11
问题 This question already has answers here : Which is more effective: if (null == variable) or if (variable == null)? [duplicate] (9 answers) Closed 6 years ago . This may just be a style question, but I'm reading a Java coding book ('Programming Android') and the writer all declares null first before a variable method, a practice I am not familiar with. For example: if (null == foo) { //code here } or if (null != foo) { //code here } instead of if (foo == null) { //code here } I can't see how

Testing for null in Powershell: Why does testing an empty array behave differently from an empty string?

余生长醉 提交于 2019-12-19 22:01:29
问题 Consider this code "Type: array" $v = @() " -eq `$null: $($v -eq $null)" " -ne `$null: $($v -ne $null)" "Type: string" $v = '' " -eq `$null: $($v -eq $null)" " -ne `$null: $($v -ne $null)" which produces the following result: Type: array -eq $null: -ne $null: Type: string -eq $null: False -ne $null: True Why does -eq and -ne behave as expected for an empty string, but evaluate to null or empty for an empty array? More importantly, how do you distinguish between $null and an empty array? 回答1:

URL.createObjectURL returns a blob with null prepended. Eg : Blob:null/12415-63

心已入冬 提交于 2019-12-19 21:52:37
问题 blob has null prepended at the start eg : blob:null/72438-4637-23673-34721. But when I use the same as a src to the , it shows up the correct image. I am using URL.createObjectURL call. I also tried using webkitURL. Both return a blob with null appended at the start. Also the blob value returned by URL and webkitURL are not the same. Here is the code snippet var dataUrl = canvas.toDataURL(); // The last piece of the data URL after the comma var byteString = atob(dataUrl.split(',')[1]); //

PowerShell $null is not null any more when calling into C# code

旧城冷巷雨未停 提交于 2019-12-19 21:11:32
问题 In PowerShell one can define C# code and execute it. Passing in $null into the following simplest function shows that not null gets passed into the function Add-Type -TypeDefinition @" public static class foo { public static void fooo(string a) { if(a!=null) { System.Console.WriteLine("Not Null. Is '" + a + "'"); } } } "@ -Language CSharp Calling it as follows leads to the output Not Null. Is ''. This shows that $null was not null in C#. Methods like 'IsNullOrEmpty' or 'IsNullOrWhiteSpace'

ArrayList automatically adding null items

倾然丶 夕夏残阳落幕 提交于 2019-12-19 18:49:20
问题 Hello everyone. I'm making a vocabulary App, in which I need to create a List<String> (or ArrayList). To do so, I've created the following piece of code (just an example): List<String> tempSOLUTION = new ArrayList<String>(); String temp = "abc123"; tempSOLUTION.add(temp); I've also tried the following: tempSOLUTION.add(new String(temp)); Both of them add the item to the list, but while debugging, I find that it's array has 12 objects, which are the following: [abc123, null, null, null, null,

Assign to an array and replace emerged nil values

烂漫一生 提交于 2019-12-19 17:14:22
问题 Greetings! When assigning a value to an array as in the following, how could I replace the nil s by 0 ? array = [1,2,3] array[10] = 2 array # => [1, 2, 3, nil, nil, nil, nil, nil, nil, nil, 2] If not possible when assigning, how would I do it the best way afterwards? I thought of array.map { |e| e.nil? ? 0 : e } , but well… Thanks! 回答1: There is no built-in function to replace nil in an array, so yes, map is the way to go. If a shorter version would make you happier, you could do: array.map {

Return null for date_format when input is null in mysql

╄→гoц情女王★ 提交于 2019-12-19 16:54:51
问题 I'm doing something like this: SELECT date_format(mydate, '%d/%m/%Y') FROM xyz; When mydate is NULL, date_format returns 00/00/0000. This is correct, but how can I make it so that it returns NULL when the input is NULL? 回答1: SELECT IF(mydate,date_format(mydate, '%d/%m/%Y'),NULL) FROM xyz; Source: http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html 回答2: You can wrap this into a IF -Clause, like this: SELECT IF(mydate,DATE_FORMAT(mydate, '%d/%m/%Y'),NULL) FROM xyz; That said, if

Powershell 2.0 generates nulls between characters

独自空忆成欢 提交于 2019-12-19 14:58:33
问题 With powershell 2.0: write-output "abcd" >> mytext.txt returns: a nul b nul c nul d nul od -c shows the nul as a true binary zero, \0 , or: a \0 b \0 c \0 d \0 (and \r \0 \n \0 ). I am trying to generate some SQL, so I don't think this will do. Any ideas of what's going on and how to use write-output to just get the specified characters? 回答1: This is because write-output defaults to UTF-16 text encoding, which is 2 bytes per character. When you are dealing with text that fits into the ASCII

Is a property default value of null the same as no default value?

纵饮孤独 提交于 2019-12-19 13:53:37
问题 And can I therefore safely refactor all instances of class Blah { // ... private $foo = null; // ... } to class Blah { // ... private $foo; // ... } ? 回答1: Simple answer, yes. See http://php.net/manual/en/language.types.null.php The special NULL value represents a variable with no value. NULL is the only possible value of type null. You can easily test by performing a var_dump() on the property and you will see both instances it will be NULL class Blah1 { private $foo; function test() { var