473,472 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Every 2 Letter Combo for Array of Strings


string[] array = new string[3] {"A","B","C"};
Given the above data, I'm trying to find C# code which will produce


A,A
B,A
C,A
A,B
B,B
C,B
A,C
B,C
C,C
Its been a long week, and I'm brain dead, and googled out.
Thanks for any help.


Feb 8 '08 #1
8 1263
Erm, loop?

string[] array = { "A", "B", "C" };
for(int i = 0; i < array.Length; i++)
for (int j = 0; j < array.Length; j++)
{
Console.WriteLine("{0},{1}", array[j], array[i]);
}

You could do something more exciting, but that should do...

Marc
Feb 8 '08 #2
Like I said dude....brain dead.
"Marc Gravell" <ma**********@gmail.comwrote in message
news:79**********************************@v4g2000h sf.googlegroups.com...
Erm, loop?

string[] array = { "A", "B", "C" };
for(int i = 0; i < array.Length; i++)
for (int j = 0; j < array.Length; j++)
{
Console.WriteLine("{0},{1}", array[j], array[i]);
}

You could do something more exciting, but that should do...

Marc

Feb 8 '08 #3
Something more exciting being (if the OP is using .NET 3.5/C# 3.0):

string[] array = { "A", "B", "C" };

IEnumerable<stringquery =
from a in array
from b in array
select a + "," + b // Could be string.Format("{0},{1}", a, b) as well if
you wish.

foreach (string item in query)
{
Console.WriteLine(item);
}

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Marc Gravell" <ma**********@gmail.comwrote in message
news:79**********************************@v4g2000h sf.googlegroups.com...
Erm, loop?

string[] array = { "A", "B", "C" };
for(int i = 0; i < array.Length; i++)
for (int j = 0; j < array.Length; j++)
{
Console.WriteLine("{0},{1}", array[j], array[i]);
}

You could do something more exciting, but that should do...

Marc

Feb 8 '08 #4
Like I said dude....brain dead.

I know that feeling;-p

Currently in "crunch"; I don't expect to be getting to sleep any time
soon...

Marc
Feb 8 '08 #5
(laughs)

I actually deliberately stopped myself posting the LINQ version, aware
(over-cautious) that LINQ isn't yet fully mainstream... oh well ;-p

Marc
Feb 8 '08 #6
IEnumerable<stringquery =
* * ...
* * select new { A1Label = a, A2Label = b, NotSame = (a != b) };
(minor; just for the OP really) - you'd need "var query" here because
of the anonymous type in the projection

Marc
Feb 8 '08 #7
Nicholas Paldino [.NET/C# MVP] wrote:
Well, in SQL, you don't have to explicitly state CROSS JOIN anymore (and
I do believe it is actually not recommended now, but I'd have to look that
up), you can just do:

select
a1.AlphabetLabel as A1Label, a2.AlphabetLabel as A2Label,
case a1.AlphabetLabel when a2.AlphabetLabel then 0 else 1 end as NotSame
from
Alphabet as a1, Alphabet as a2
CROSS JOIN was introduced in SQL-92 to solve some ambiguity problems with
the comma notation and increase clarity (before this you couldn't use them,
so it's not a case of "not having to state it anymore"; the comma notation
came first). I'm not aware of any explicit recommendation for or against,
and either syntax will work fine.

However, it's still a very good idea to write out the CROSS JOIN explicitly,
since it's the most uncommon form of join (even if it's the most natural
one, mathematically speaking) and alerting your fellow developer to its use
is a good idea. An "accidental" cross join is not a good thing to have (as
even moderately-sized tables will produce enormous result sets) which is
exactly why ANSI SQL introduced explicit syntax for them.

--
J.
Feb 8 '08 #8
that'd better not be a ghost-busters joke!
Feb 8 '08 #9

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

Similar topics

4
by: Rod | last post by:
I have an Access database with the 3 fields in , , I create a dataset and bind a form to it, no problem. I now want to put in a combo box to search on name. Now I can do this fine if I just...
6
by: Fungii | last post by:
Hello, I have a stylesheet that sets p:first-letter to a certain size and colour. I was playing around with Javascript to change paragraph stylesheets using an array like this: var paras =...
14
by: Mr.Clean | last post by:
I have a string. I'd like to take this string and make each char change until it gets to another char at the same position of the string. Example: Original String: " NEW YORK " Final...
2
by: dixie | last post by:
I have a combo box on a form that contains some text of the type "Warning Letter 3" (this is the bound field). I want to take the last character from the contents of this combo box and place it in...
7
by: Micheal Artindale | last post by:
I am looking at creating list of letter combinations. letters a-h 6 letters per combination letter can repeat its self in the combination, but not next to its self and, a series of letter can...
3
by: Kannan | last post by:
hi Currently I am working in C# windows application. I am trying to fill combo box with values We have to always use datasource property for filling values in Combo box? In VB, normally i have...
9
by: booksnore | last post by:
I am writing some code to search for strings that contain every letter of the alphabet. At the moment I am using the method below to check to see if a string contains every letter of the alphabet....
5
by: mythili123 | last post by:
Hi I have difficult undersating this problem Read data from a I/P file.Ignore all lines that start with the literal string given as a command line argument. Otherwise, collect and count the...
2
by: Doug | last post by:
Hi I have a list of about 50 text items (strings) that I would like to add to about 5 combo boxes at various times depending on if a user clicks on the OK button. I have tried to code an...
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,...
1
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
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,...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.