Null checking and if-blocks
this complaining possible null reference temp on line 7.
function test(byval source as ienumerable(of byte), byval format as string) as string | |
dim temp = trycast(source, icollection(of byte)) | |
dim result | |
if temp is nothing or format is nothing then | |
result = new text.stringbuilder() | |
else | |
result = new text.stringbuilder(temp.count * format.length) | |
end if | |
return result.tostring | |
end function |
hi jonathan,
for disjunctive conditions, want use orelse, not bitwise or operation. way, static checker can determine different control paths.
function test(byval source as ienumerable(of byte), byval format as string) as string |
dim temp = trycast(source, icollection(of byte)) |
dim result |
if temp is nothing orelse format is nothing then |
result = new text.stringbuilder() |
else |
result = new text.stringbuilder(temp.count * format.length) |
end if |
return result.tostring |
end function |
with orelse, checker figures out.
-maf
DevLabs > Code Contracts
Comments
Post a Comment