fork download
  1. using System;
  2. using System.Linq;
  3.  
  4. public class Test
  5. {
  6. public static void Main() {
  7. string[] tests = { "a", 1.ToString(), "321", "xyz" };
  8. foreach (var test in tests) {
  9. Console.WriteLine(test.ToChar());
  10. }
  11. }
  12. }
  13.  
  14. public static class StringExtensions {
  15. public static char ToChar(this string value) {
  16. if (string.IsNullOrEmpty(value)) throw new ArgumentException();
  17. return value.First();
  18. }
  19. }
Success #stdin #stdout 0.02s 15784KB
stdin
Standard input is empty
stdout
a
1
3
x