473,398 Members | 2,343 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,398 software developers and data experts.

Join

Hello,

I have a List<Role>, Roles, where Role has two properties: Type and
Description. Then I have: string [] MyRoles.

I need to define a CSV list created by all Desciptions of the
List<Rolewhich type is contained in string [] MyRoles.

string RolesCSV = Roles.Join(",", r =MyRoles.Contains(r.Type));

I get:
String[] does not contain a definition Contains.

.... But it is in the list as I right ...

What am I doing wrong?

Thanks,
Miguel
Nov 17 '08 #1
5 2556
On Mon, 17 Nov 2008 10:45:11 -0800, shapper <md*****@gmail.comwrote:
I have a List<Role>, Roles, where Role has two properties: Type and
Description. Then I have: string [] MyRoles.

I need to define a CSV list created by all Desciptions of the
List<Rolewhich type is contained in string [] MyRoles.

string RolesCSV = Roles.Join(",", r =MyRoles.Contains(r.Type));

I get:
String[] does not contain a definition Contains.

... But it is in the list as I right ...

What am I doing wrong?
You're not showing enough code, for one. You're also not quoting the
exact compile error you got, for another.

That said, if the Type property of the Role class isn't of type string,
you may be getting an error that simply points out there's not an
appropriate overload of Contains(). Just because there's _a_ method of
that name doesn't mean it's a method that suits the parameters you tried
to pass in.

If that doesn't help you, you really should post a concise-but-complete
code sample that demonstrates the issue.

Pete
Nov 17 '08 #2
On Nov 17, 1:45*pm, shapper <mdmo...@gmail.comwrote:
Hello,

I have a List<Role>, Roles, where Role has two properties: Type and
Description. Then I have: string [] MyRoles.

I need to define a CSV list created by all Desciptions of the
List<Rolewhich type is contained in string [] MyRoles.

string RolesCSV = Roles.Join(",", r =MyRoles.Contains(r.Type));

I get:
String[] does not contain a definition Contains.

... But it is in the list as I right ...

What am I doing wrong?

Thanks,
Miguel
Hi,

IIRC Array does not have a member Contains, you cuold use Find
instead:
Roles.Select( (r)=MyRoles.Find(r)!=null)
Nov 17 '08 #3
shapper wrote:
I have a List<Role>, Roles, where Role has two properties: Type and
Description. Then I have: string [] MyRoles.

I need to define a CSV list created by all Desciptions of the
List<Rolewhich type is contained in string [] MyRoles.

string RolesCSV = Roles.Join(",", r =MyRoles.Contains(r.Type));

I get:
String[] does not contain a definition Contains.
Even if there were, you code makes no sense. .Contains() returns a boolean,
the .Join() method you're invoking doesn't take two arguments, and
..Description isn't anywhere.

Try

string RolesCSV = string.Join(",", (from r in Roles where
MyRoles.Contains(r.Type) select r.Description).ToArray());

If that still fails to compile, you need "using System.Linq;" at the top.

--
J.
Nov 17 '08 #4
On Nov 17, 7:39*pm, Jeroen Mostert <jmost...@xs4all.nlwrote:
shapper wrote:
I have a List<Role>, Roles, where Role has two properties: Type and
Description. Then I have: string [] MyRoles.
I need to define a CSV list created by all Desciptions of the
List<Rolewhich type is contained in string [] MyRoles.
string RolesCSV = Roles.Join(",", r =MyRoles.Contains(r.Type));
I get:
String[] does not contain a definition Contains.

Even if there were, you code makes no sense. .Contains() returns a boolean,
the .Join() method you're invoking doesn't take two arguments, and
.Description isn't anywhere.

Try

* *string RolesCSV = string.Join(",", (from r in Roles where
MyRoles.Contains(r.Type) select r.Description).ToArray());

If that still fails to compile, you need "using System.Linq;" at the top.

--
J.
I am trying to use the following sintax:

string b = string.Join(", ", Roles.Where(r =MyRoles.Contains
(r.Type.ToString()) == true).Select(r =r.Description).ToArray());

Again I keep having the error:
'string[]' does not contain a definition for 'Contains' and the best
extension method overload 'MyApp.Mvc.ViewDataPaper.Contains
(System.Web.Mvc.ViewDataDictionary, System.Type)' has some invalid
arguments

And I can't find the method Find for MyRoles ... only Contains.
Nov 17 '08 #5
On Mon, 17 Nov 2008 13:21:16 -0800, shapper <md*****@gmail.comwrote:
I am trying to use the following sintax:

string b = string.Join(", ", Roles.Where(r =MyRoles.Contains
(r.Type.ToString()) == true).Select(r =r.Description).ToArray());

Again I keep having the error:
'string[]' does not contain a definition for 'Contains' and the best
extension method overload 'MyApp.Mvc.ViewDataPaper.Contains
(System.Web.Mvc.ViewDataDictionary, System.Type)' has some invalid
arguments
As I said, you need to post a concise-but-complete code example.

The error indicates that you have your own extension method declared
somewhere (in the MyApp.Mvc.ViewDataPaper class) by the name of
Contains(), and for some reason that's the one that chosen as the "best"
overload for the parameters you're passing. That particular overload
takes "System.Type", not "System.String" as an argument, and applies to
objects typed as "System.Web.Mvc.ViewDataDictionary" instead of
"System.Array" or (if you were using the LINQ extension method)
"IEnumerable<String>" (assuming "MyRoles" really is a String[], which
given the overload that the compiler believes is the best match is hardly
safe to assume at this point).

You cannot expect to get precise, useful answers if you don't bother to
post a concise-but-complete code example. All you're showing are tiny
little glimpses of code that is apparently changing from post to post.
There's no way to provide a definitive answer with that kind of input.

Pete
Nov 17 '08 #6

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

Similar topics

0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
2
by: Bruce Duncan | last post by:
I'm a bit new to MySQL (know MS SQL well...and that may be the problem...getting the syntax confused) and I'm having a join problem...can anyone offer some help? Here's my problem: I have table1...
3
by: Ike | last post by:
Oh I have a nasty query which runs incredibly slowly. I am running MySQL 4.0.20-standard. Thus, in trying to expedite the query, I am trying to set indexes in my tables. My query requires four...
1
by: Beachvolleyballer | last post by:
hi there anyone had an idea to join following 2 queries to 1???? ----- QUERY 1 --------------------------------------------- SELECT TMS_CaseF_2.Name AS TCDomain_0, TMS_CaseF_3.Name AS...
8
by: Matt | last post by:
Hello I have to tables ar and arb, ar holds articles and a swedish description, arb holds descriptions in other languages. I want to retreive all articles that match a criteria from ar and...
7
by: Greg | last post by:
I'm a quantitative securities analyst working with Compustat data (company fiscal reports and pricing feeds). My coworker came across a problem that we fixed, but I'd like to understand 'why' it...
3
by: Ian Boyd | last post by:
i know nothing about DB2, but i'm sure this must be possible. i'm trying to get a client to create a view (which it turns out is called a "Logical" in DB2). The query needs a LEFT OUTER JOIN, but...
12
by: Phil Powell | last post by:
<cfquery name="getAll" datasource="#request.dsn#"> SELECT U.userID, U.fname, U.lname, U.phone, U.lastLoggedIn, U.choiceId, U.experience, T.label AS teamLabel, R.label AS roleLabel FROM User U...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
12
by: Chamnap | last post by:
Hello, everyone I have one question about the standard join and inner join, which one is faster and more reliable? Can you recommend me to use? Please, explain me... Thanks Chamnap
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.