Length and Indexer

   
 

using System;
using System.Text;

class MainClass
{
    public static string ReverseString(string str)
    {
       if (str == null || str.Length <= 1) 
       {
            return str;
       }

       StringBuilder revStr = new StringBuilder(str.Length);


       for (int count = str.Length - 1; count > -1; count--)
       {
           revStr.Append(str[count]);
       }

       return revStr.ToString();
   }
   public static void Main(){
       Console.WriteLine(ReverseString("Madam Im Adam"));
       Console.WriteLine(ReverseString("The quick brown fox jumped over the lazy dog."));
   }
}

    


Get Text Element Enumerator


   


using System;
using System.Globalization;
using System.Threading;

class Class1 {
  static void Main(string[] args) {
         TextElementEnumerator Iter;
         String MyStr, OutBuf;

         MyStr = "The Quick programmer ran rings around the lazy manager";

         //Lets do the iterator thing
         Iter = StringInfo.GetTextElementEnumerator(MyStr);
         while (Iter.MoveNext())
         {
            OutBuf = "Character at position " + 
                     Iter.ElementIndex.ToString() + 
                     " = " + Iter.Current;
            Console.WriteLine(OutBuf);
         }
   }
}

           
          


Use Stopwatch

   


using System;
using System.Reflection;
using System.Diagnostics;

class OnlyLoad {
    static void Main() {
        Stopwatch duration = new Stopwatch();
        duration.Reset();
        duration.Start();
        Assembly a = Assembly.Load("library");
        duration.Stop();
        Console.WriteLine(duration.ElapsedTicks.ToString());
        duration.Reset();
        duration.Start();
        a = Assembly.ReflectionOnlyLoad("library");
        duration.Stop();
        Console.WriteLine(duration.ElapsedTicks.ToString());
    }
}
           
          


new SoundPlayer(openDialog.FileName) Play

   
 
using System;
using System.Windows.Forms;
using System.Media;

public class MainClass {
    public static void Main() {
        // Allow the user to choose a  file.
        OpenFileDialog openDialog = new OpenFileDialog();
        openDialog.Filter = "WAV Files|*.wav|All Files|*.*";

        if (DialogResult.OK == openDialog.ShowDialog()) {
            SoundPlayer player = new SoundPlayer(openDialog.FileName);

            try {
                player.Play();
            } catch (Exception) {
                MessageBox.Show("An error occurred while playing media.");
            } finally {
                player.Dispose();
            }
        }
    }
}