title: how to reverse a words in a string using c# programming?
body: <p>I want reverse words in a string. I am not getting proper output. Please help me.</p>
  
  <p>Example</p>
  
  <ul>
  <li>input: <code>Hello world</code></li>
  <li>output: <code>World Hello</code>  </li>
  </ul>
  
  <p>Code:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          Console.WriteLine("Enter a string");
          string s1 = Console.ReadLine();           
          string s2 = "";
          int l = s1.Length;
  
          for (int i = l - 1; i &gt;= 0; i--)
          {
              s2 = s2 + s1[i];
          } 
          for (int i = 0; i&lt;s2.Length; i++)
          {
              if (s2[i] == ' ')
              {
                  for(int j=i;j&gt;0 &amp;&amp; s2[j]!=' ';j--)
                     Console.Write(s2[j1]);
                     Console.Write(" ");
              }
              else if (i == s2.Length - 1)
              {
                  for (int j = i+1; j &gt; 0 &amp;&amp; s2[j] != ' '; j--)
                      Console.Write(s2[j]);
                  Console.Write(" ");
              }                   
          }
      }
  } 
  </code></pre>