title: How to Format a String
body: <p>In my app I am determining network changes as they occur. I have some sample code that I was using but I would like to format the resulting string in a certain manner</p>
  
  <pre><code>string change = string.Empty;
          switch (e.NotificationType)
          {
              case NetworkNotificationType.InterfaceConnected:
                  change = "Connected to ";
                  break;
              case NetworkNotificationType.InterfaceDisconnected:
                  change = "Disconnected from ";
                  break;
              case NetworkNotificationType.CharacteristicUpdate:
                  change = "Characteristics changed for ";
                  break;
              default:
                  change = "Unknown change with ";
                  break;
          }
  
          string changeInformation = String.Format(" {0} {1} {2} ({3})",
                      DateTime.Now.ToString(), change, e.NetworkInterface.InterfaceName,
                      e.NetworkInterface.InterfaceType.ToString());
  
          // We are making UI updates, so make sure these happen on the UI thread.
          Dispatcher.BeginInvoke(() =&gt;
          {
              Changes.Add(changeInformation); //Changes contains the changeInformation
          });
  </code></pre>
  
  <p>Currently the result looks like</p>
  
  <p><img src="https://i.stack.imgur.com/D6WRK.png" alt="enter image description here"></p>
  
  <p>but this is not formatted well at all, and tends to get jumbled at times. I'd like to be able to format it so that <code>DateTime.Now.ToString()</code> is on the top line, then the <code>change</code> on the next line, followed by <code>e.NetworkInterface.InterfaceName</code> and <code>e.NetworkInterface.InterfaceType.ToString()</code>. How could I do this?</p>