473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

String Array

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();

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

Thanks,
Miguel
Oct 14 '08 #1
1 1437
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
Oct 14 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Don Starr | last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string (including nul), or the size of a pointer? For example, assuming a char is 1 byte and a char *...
7
by: al | last post by:
char s = "This string literal"; or char *s= "This string literal"; Both define a string literal. Both suppose to be read-only and not to be modified according to Standard. And both have...
4
by: songkv | last post by:
Hi, I am trying to reassign an array of char to a string literal by calling a function. In the function I use pointer-to-pointer since I want to reassign the "string array pointer" to the string...
22
by: spike | last post by:
How do i reset a string? I just want to empty it som that it does not contain any characters Say it contains "hello world" at the time... I want it to contain "". Nothing that is.. Thanx
4
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where...
14
by: Bob | last post by:
I have a function that takes in a list of IDs (hundreds) as input parameter and needs to pass the data to another step as a comma delimited string. The source can easily create this list of IDs in...
8
by: Jeff Johnson | last post by:
Hi, I've begun converting an ASP site over to .NET and I'm a novice at both the new platform as well as C#. I have a COM+ object that returns a string array when it is called. The size of...
17
by: Chad Myers | last post by:
I've been perf testing an application of mine and I've noticed that there are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String instances being created. I've done some...
11
by: Zordiac | last post by:
How do I dynamically populate a string array? I hope there is something obvious that I'm missing here Option Strict On dim s() as string dim sTmp as string = "test" dim i as integer ...
14
by: Shhnwz.a | last post by:
Hi, I am in confusion regarding jargons. When it is technically correct to say.. String or Character Array.in c. just give me your perspectives in this issue. Thanx in Advance.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.