Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure why this question got voted down so much, but perhaps the reason is you have a very clear algorithm already, so it should be trivial to get the C# code. As it stands, either you're either really inexperienced or really lazy. I'm going to assume the former.</p> <p>Anyways, lets walk through the requirements.</p> <p>1) "I then have a list of words List." you have this line in some form already.</p> <pre><code>List&lt;string&gt; words = GetListOfWords(); </code></pre> <p>2) "go through the words and add them to the dictionary starting at Item1" -- I'd recommend a List instead of a dictionary, if you're going for a sequence of strings. Also, you'll need a temporary variable to store the contents of the current line, because you're really after adding a full line at a time.</p> <pre><code>var lines = new List&lt;string&gt;(); string currentLine = ""; </code></pre> <p>3) "I need a loop that will go through the words"</p> <pre><code>foreach(var word in words) { </code></pre> <p>4) " If the new item and the current item's length added together is greater than 50 characters" -- +1 for the space.</p> <pre><code> if (currentLine.Length + word.Length + 1 &gt; 50) { </code></pre> <p>5) "then the word needs to move down to the next line "</p> <pre><code> lines.Add(currentLine); currentLine = word; } </code></pre> <p>6) " go through the words and add them to the dictionary starting at Item1 " -- you didn't phrase this very clearly. What you meant was you want to join each word to the last line unless it would make the line exceed 50 characters.</p> <pre><code> else { currentLine += " " + word; } } lines.Add(currentLine); // the last unfinished line </code></pre> <p>and there you go. </p> <hr> <p>If you absolutely need it as an IDictionary with 3 lines, just do</p> <pre><code>var dict = new Dictionary&lt;string,string&gt;(); for(int lineNum = 0; lineNum &lt; 3; lineNum ++) dict["Address"+lineNum] = lineNume &lt; lines.Length ? lines[lineNum] : ""; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload