using System.Collections.Generic;
public static void Main()
string sample = "lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
char? result = FirstNonRepeatedCharacter(sample);
Console.WriteLine("'{0}' is the first non-repeated character in the string \"{1}\"", result, sample);
public static char? FirstNonRepeatedCharacter(string text)
if(string.IsNullOrEmpty(text)
Dictionary<char, int> strIdentifier = new Dictionary<char, int>();
for(int i=0; i < text.Length; i++)
if(strIdentifier.ContainsKey(text[i]))
strIdentifier[text[i]]++;
strIdentifier.Add(text[i], 1);