diff --git a/ExtensionMethods/App.config b/ExtensionMethods/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/ExtensionMethods/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ExtensionMethods/ExtensionMethods.csproj b/ExtensionMethods/ExtensionMethods.csproj new file mode 100644 index 0000000..13d9f0a --- /dev/null +++ b/ExtensionMethods/ExtensionMethods.csproj @@ -0,0 +1,54 @@ + + + + + Debug + AnyCPU + {7EAB276E-2494-4BA6-BB91-2ADFD22FE331} + Exe + ExtensionMethods + ExtensionMethods + v4.6.1 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ExtensionMethods/Program.cs b/ExtensionMethods/Program.cs new file mode 100644 index 0000000..d03aa8d --- /dev/null +++ b/ExtensionMethods/Program.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ExtensionMethods +{ + class Program + { + static void Main(string[] args) + { + string post = "This is supposed to be a very long blog post blah blah blah..."; + var shortenedPost = post.Shorten(5); + + IEnumerable numbers = new List() { 1, 3, 7 , 4 ,9,20,22}; + var max = numbers.Max(); + System.Console.WriteLine(max); + System.Console.WriteLine(shortenedPost); + } + } +} diff --git a/ExtensionMethods/Properties/AssemblyInfo.cs b/ExtensionMethods/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d362f75 --- /dev/null +++ b/ExtensionMethods/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ExtensionMethods")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ExtensionMethods")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("7eab276e-2494-4ba6-bb91-2adfd22fe331")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ExtensionMethods/StringExtensions.cs b/ExtensionMethods/StringExtensions.cs new file mode 100644 index 0000000..07d121a --- /dev/null +++ b/ExtensionMethods/StringExtensions.cs @@ -0,0 +1,23 @@ +using System; +using System.Linq; + +namespace ExtensionMethods +{ + public static class StringExtensions + { + public static string Shorten(this String str, int numberOfWords) + { + if (numberOfWords < 0) + throw new ArgumentOutOfRangeException("numberOfWords should be greater or equal to 0."); + if (numberOfWords == 0) + return ""; + + var words = str.Split(' '); + + if (words.Length <= numberOfWords) + return str; + + return string.Join(" ", words.Take(numberOfWords))+"..."; + } + } +} diff --git a/TrainingAdvancedTechniques.sln b/TrainingAdvancedTechniques.sln index 94ffda2..e46beab 100644 --- a/TrainingAdvancedTechniques.sln +++ b/TrainingAdvancedTechniques.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BooksLambda", "BooksLambda\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VideoEnc", "VideoEnc\VideoEnc.csproj", "{8B61AEAF-981F-4509-A550-2DA29838DF66}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExtensionMethods", "ExtensionMethods\ExtensionMethods.csproj", "{7EAB276E-2494-4BA6-BB91-2ADFD22FE331}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {8B61AEAF-981F-4509-A550-2DA29838DF66}.Debug|Any CPU.Build.0 = Debug|Any CPU {8B61AEAF-981F-4509-A550-2DA29838DF66}.Release|Any CPU.ActiveCfg = Release|Any CPU {8B61AEAF-981F-4509-A550-2DA29838DF66}.Release|Any CPU.Build.0 = Release|Any CPU + {7EAB276E-2494-4BA6-BB91-2ADFD22FE331}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7EAB276E-2494-4BA6-BB91-2ADFD22FE331}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7EAB276E-2494-4BA6-BB91-2ADFD22FE331}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7EAB276E-2494-4BA6-BB91-2ADFD22FE331}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE