vb.net - LINQ .Startswith or .Contains problems in VB.NET4 -
This can be a newbie question ...
In my code I can easily "Ob. See "Fade = String", but "Obj. Fails." ("A") does not work by using the following two functions:
Public Function EntriesByFileName (Database ByRef () entry , As byval file name _ string as the name) IEnumerable (login) retarded results as IEnumerable (as entered) = from EntryObject in database- _ (EntryObject.FileName = File Name) Select EntryObject Return Results Expiration Function Public Function EntriesLikeFileName (Database () entry, ByRal _ as the name of the file as the name string) IEnumerable (login) as file name = Filename.ToLower Blind Result as the IEnumerable (Entry) = EntryObject in the database _ Where EntryObject.FileName.StartsWith ("A") Select EntryObject Return Result Ending Function
The first function (ByFileName) works fine. Second function (eg Filename does not use the "Startswith" object that I receive is not set for an instance of an object object. "What am I doing wrong?
EntryObject.FileName
can be zero
, then EntryObject.FileName.StartsWith (..)
a NullReferenceException
< / P>
Zero
such as
if EntryObject.FileName & lt; Change the condition for the first check; & Gt; Nothing andalso using EntryObject.FileName.StartsWith (..)
andalso
here short circuit, which means that if the first condition is not meeting Is employed, the second will not be evaluated and therefore we can not get the NullReferenceException
.
Comments
Post a Comment