Created
August 19, 2020 19:46
-
-
Save bergpb/6eadcf9bd01e5f3dc01e328437cc6049 to your computer and use it in GitHub Desktop.
Outro exemplo de Extension Methods no C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System | |
| public class ProcessFile | |
| { | |
| public static void Main() | |
| { | |
| string s1 = "Good morning dear students"; | |
| Console.WriteLine(s1.Cut(0)); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace System | |
| static class StringExtensions | |
| { | |
| public static string Cut(this string thisObj, int count) | |
| { | |
| if(thisObj.Lenght <= count) | |
| { | |
| return thisObj; | |
| } | |
| else | |
| { | |
| return thisObj.Substring(0, count) + "..."; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment