I am having a program which would first iterate through the File data and then would convert the (JSON) data to an Object. Object depends on the File that I'm trying to access the data from. That's pretty much unrelated to the question I'm going to ask.
When I complete the project, and I was ready to send it to my friends, I found that there was one thing I didn't understand regarding the List<>
s of C#.
Here is the code I'm using:
// File is not empty!
string file = File.ReadAllText(new MainWindow().getFileName("events"));
List<Event> events = JsonConvert.DeserializeObject<List<Event>>(file);
After this, I'm trying to populate the ListView
by each event I'm having, or I'm trying to populate a TextBlock
with a text saying, there is no event create one now.
I'm using this condition.
if(events != null) {
// goes well
} else {
// populate the code text view
}
In this code, the else block doesn't get triggered. If there are events, it populates the list otherwise it just skips the textView update code.
But, if I use this code instead,
if(events.Count != 0) {
// listview code..
} else {
// populate text view
}
Using this, I can populate the textView and I can see the error message in the Page.
I have added the code image, and the working example for that. Hope someone can tell me the difference
(List.Count == 0) || (List == null)
/* irrelevant piece of code, I'm trying to ask, should I use
* List Count == 0 OR List is equal to null */