Guest User

Untitled

a guest
Aug 21st, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. Removing the class name before calling a custom function?
  2. public class Class1
  3. {
  4. public static string UppercaseFirst(string s)
  5. {
  6. // Check for empty string.
  7. if (string.IsNullOrEmpty(s))
  8. {
  9. return string.Empty;
  10. }
  11. // Return char and concat substring.
  12. return char.ToUpper(s[0]) + s.Substring(1).ToLower();
  13. }
  14. }
  15.  
  16. string MyName = "john";
  17. string result = Class1.UppercaseFirst(MyName)
  18.  
  19. Result: "John"
  20.  
  21. public static string UppercaseFirst(this string s)
  22. {...
  23.  
  24. public static class StringExtension
  25. {
  26. public static string UppercaseFirst(this string text)
  27. {
  28. // ..
  29. }
  30. }
  31.  
  32. string uppercase = "myText".UppercaseFirst();
Add Comment
Please, Sign In to add comment