list1 = new List(); list.Add("a"); li...">

Printing List Items

List<string> list = new List<string>(); list.Add("A"); list.Add("B"); List<string> list1 = new List<string>(); list.Add("a"); list.Add("b"); for (int i = 0; i < list.Count; i++) { // print another list items. for (int j = 0; j < list1.Count; j++) { Console.WriteLine("/" + list[i] + "/" + list1[j]); } } 

I want to make the code as follows string tmpS =+ list[i]; to join the next sum of list items.

then type tmpS

but compilation error CS0023: the '+' operator cannot be applied to an operand of type 'string'.

How to print all the items below (any view is ok)

Aa Ab Aab Aba AB Aba Ducks ABAB ABBA To Ba Bb Baba BBA

(Caps no swap number. Small characters should be replaced and always follow Caps Numbers. Add small characters.)

+7
c # data-structures
source share
3 answers

it does a lot of time, I did not work on a pure algorithmic problem!

This program should do the trick:

 class Program { static void Main(string[] args) { List<string> uppers = new List<string>(); uppers.Add("A"); uppers.Add("B"); List<string> lowers = new List<string>(); lowers.Add("a"); lowers.Add("b"); List<string> combinedUppers = GetCombinedItems(uppers); List<string> combinedLowers = GetCombinedItems(lowers); List<string> combinedUppersLowers = GetCombinedList(combinedUppers, combinedLowers); foreach (string combo in combinedUppersLowers) { Console.WriteLine(combo); } Console.Read(); } static private List<string> GetCombinedItems(List<string> list) { List<string> combinedItems = new List<string>(); for (int i = 0; i < list.Count; i++) { combinedItems.Add(list[i]); for (int j = 0; j < list.Count; j++) { if (list[i] != list[j]) { combinedItems.Add(String.Format("{0}{1}", list[i], list[j])); } } } return combinedItems; } static private List<string> GetCombinedList(List<string> list1, List<string> list2) { List<string> combinedList = new List<string>(); for (int i = 0; i < list1.Count; i++) { combinedList.Add(list1[i]); for (int j = 0; j < list2.Count; j++) { combinedList.Add(String.Format("{0}{1}", list1[i], list2[j])); } } for (int i = 0; i < list2.Count; i++) { combinedList.Add(list2[i]); for (int j = 0; j < list1.Count; j++) { combinedList.Add(String.Format("{0}{1}", list2[i], list1[j])); } } return combinedList; } } 

Sincerely.


This program gives you this result:

a Aa Aab Ab aba AB aba ABAB ducks ABBA In Ba Baba Bb BBA BA bleat BÀAB Baba rum baba aA aAB abA aba aba ABAB ducks ABBA b ba Baba bb BBA ba blea BÀAB Baba Baba

+3
source share

It smells of homework.

 List<string> list = new List<string>(); list.Add("A"); list.Add("B"); List<string> list1 = new List<string>(); list.Add("a"); list.Add("b"); string xxx = ""; for (int i = 0; i < list.Count; i++) { xxx += list[i]; Console.WriteLine(xxx); // print another list items. for (int j = 0; j < list1.Count; j++) { Console.WriteLine("/" + list[i] + "/" + list1[j]); } } 
+3
source share

This is += not =+ .

But you should still use StringBuilder.

+3
source share

All Articles