On Tue, 14 Oct 2008 15:45:49 -0700, shapper <md*****@gmail.comwrote:
Hello,
I have a function that queries a database and returns a list:
return roles.Where(r =(rolesForUser.Contains(r.Type.ToString()) ||
rolesForUser == null).OrderBy(r =r.Description).ToList();
How does that even compile? You have mis-matched parens.
rolesForUser is string[]
When I don't want to account this for filter I just pass null but I
get an error.
Can't I pass a string[] as null?
How should I pass it if I don't want to pass any data and what should
I use to replace the condition:
rolesForUser == null
From the code you posted (such as it is), it seems to me that if you just
switched the two clauses in your condition so that it reads "rolesForUser
== null || rolesForUser.Contains(r.Type.ToString())" instead, your error
would go away. Hard to say for sure though, since you didn't bother to
say anything about the actual error you're getting. And since we don't
know what output you actually want, just avoiding the error isn't
necessarily the whole answer.
More generally, you need to get into the habit of asking better
questions. You didn't post barely any code (and not any that would show
how the parameter is passed or used), you didn't describe the exact error
you got, nor did you describe what behavior you would expect when you pass
null.
If you ask a garbage question, the best you can hope for is a garbage
answer. Sometimes a person's psychic debugging skills kick in and you get
lucky. But you shouldn't count on it, and in any case garbage questions
make it seems as though you don't really care enough about the answer to
put any work into the question. Surely that's not the impression you
intend.
Pete