From e2be1a3a175ded45a1b0922607d987a868367a0d Mon Sep 17 00:00:00 2001 From: Bader Bamari Date: Sun, 31 Oct 2021 21:37:33 +0300 Subject: Update C Sharp markdown. (#4260) --- csharp.html.markdown | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) (limited to 'csharp.html.markdown') diff --git a/csharp.html.markdown b/csharp.html.markdown index b965c2d4..ddb0c62a 100644 --- a/csharp.html.markdown +++ b/csharp.html.markdown @@ -12,9 +12,9 @@ contributors: filename: LearnCSharp.cs --- -C# is an elegant and type-safe object-oriented language that enables developers to build a variety of secure and robust applications that run on the .NET Framework. +C# is an elegant and type-safe object-oriented language that enables developers to build a variety of secure and robust applications that run on the cross-platform .NET framework. -[Read more here.](https://docs.microsoft.com/dotnet/csharp/getting-started/introduction-to-the-csharp-language-and-the-net-framework) +[Read more here.](https://docs.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/) ```c# // Single-line comments start with // @@ -29,7 +29,7 @@ Multi-line comments look like this /// /// This is some parameter documentation for firstParam /// Information on the returned value of a function -public void MethodOrClassOrOtherWithParsableHelp(string firstParam) {} +public void MethodOrClassOrOtherWithParsableHelp(string firstParam) { } // Specify the namespaces this source code will be using // The namespaces below are all part of the standard .NET Framework Class Library @@ -48,6 +48,10 @@ using System.Data.Entity; // Namespaces define scope to organize code into "packages" or "modules" // Using this code from another source file: using Learning.CSharp; + +// You can also do this in C# 10, it is called file-scoped namespaces. +// namespace Learning.CSharp; + namespace Learning.CSharp { // Each .cs file should at least contain a class with the same name as the file. @@ -341,8 +345,17 @@ on a new line! ""Wow!"", the masses cried"; // Convert Integer To String // Convert class has a number of methods to facilitate conversions + + // String to int + + // Better + bool result = int.TryParse(string, out var integer) + int.Parse(string); + + // Not recommended Convert.ToString(123); - // or + + // Int to string tryInt.ToString(); // Casting @@ -375,6 +388,9 @@ on a new line! ""Wow!"", the masses cried"; Console.Read(); } // End main method + // Available in C# 9 and later, this is basically a syntactic sugar for a class. Records are immutable*. + public record ARecord(string Csharp); + // CONSOLE ENTRY - A console application must have a main method as an entry point public static void Main(string[] args) { @@ -1299,16 +1315,27 @@ namespace Csharp7 ``` ## Topics Not Covered +✨ New, 👍 Old, 🎈 LTS, 🔥 Cross-platform, 🎁 Windows-only * Attributes - * async/await + + * Asynchronous Programming + * Web Development - * ASP.NET MVC & WebApi (new) - * ASP.NET Web Forms (old) - * WebMatrix (tool) + * ASP.NET Core ✨ + * Desktop Development - * Windows Presentation Foundation (WPF) (new) - * Winforms (old) + * Windows Presentation Foundation 👍 🎈 🎁 + * Universal Windows Platform ✨ 🎁 + * Uno Platform 🔥 ✨ + * WinForms 👍 🎈 🎁 + * Avalonia 🔥 ✨ + * WinUI ✨ 🎁 + +* Cross-platform Development + * Xamarin.Forms 👍 + * MAUI ✨ + ## Further Reading -- cgit v1.2.3 From 772f8ba1cdabf85e807d82c123caebe8e4851605 Mon Sep 17 00:00:00 2001 From: Jelte Fennema Date: Mon, 3 Jan 2022 17:11:11 +0100 Subject: Use correct name for enum in comment (#4188) The name used in the comment for the BikeBrand enum was incorrect. --- csharp.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'csharp.html.markdown') diff --git a/csharp.html.markdown b/csharp.html.markdown index ddb0c62a..c85acb1b 100644 --- a/csharp.html.markdown +++ b/csharp.html.markdown @@ -760,7 +760,7 @@ on a new line! ""Wow!"", the masses cried"; Gitane // 43 } // We defined this type inside a Bicycle class, so it is a nested type - // Code outside of this class should reference this type as Bicycle.Brand + // Code outside of this class should reference this type as Bicycle.BikeBrand public BikeBrand Brand; // After declaring an enum type, we can declare the field of this type @@ -1348,4 +1348,4 @@ namespace Csharp7 * [LINQ Pocket Reference](http://shop.oreilly.com/product/9780596519254.do) * [Windows Forms Programming in C#](http://www.amazon.com/Windows-Forms-Programming-Chris-Sells/dp/0321116208) * [freeCodeCamp - C# Tutorial for Beginners](https://www.youtube.com/watch?v=GhQdlIFylQ8) - \ No newline at end of file + -- cgit v1.2.3 From c0e5292022e4885619a91b0353e5fd83c457feed Mon Sep 17 00:00:00 2001 From: Marcel Ribeiro-Dantas Date: Tue, 2 Aug 2022 23:23:36 -0300 Subject: Update to uppercase for c++ and c# in index --- csharp.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'csharp.html.markdown') diff --git a/csharp.html.markdown b/csharp.html.markdown index c85acb1b..4f9b71ce 100644 --- a/csharp.html.markdown +++ b/csharp.html.markdown @@ -1,5 +1,5 @@ --- -language: c# +language: C# contributors: - ["Irfan Charania", "https://github.com/irfancharania"] - ["Max Yankov", "https://github.com/golergka"] -- cgit v1.2.3 From 322122c80fe35386ad03dc9312d1ef31e8232831 Mon Sep 17 00:00:00 2001 From: Boris Verkhovskiy Date: Fri, 19 Aug 2022 11:45:25 -0700 Subject: Proofread parts of C# --- csharp.html.markdown | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'csharp.html.markdown') diff --git a/csharp.html.markdown b/csharp.html.markdown index 4f9b71ce..1d7d0881 100644 --- a/csharp.html.markdown +++ b/csharp.html.markdown @@ -158,7 +158,7 @@ on a new line! ""Wow!"", the masses cried"; // Arrays - zero indexed // The array size must be decided upon declaration - // The format for declaring an array is follows: + // The format for declaring an array is // [] = new []; int[] intArray = new int[10]; @@ -172,7 +172,7 @@ on a new line! ""Wow!"", the masses cried"; // Lists // Lists are used more frequently than arrays as they are more flexible - // The format for declaring a list is follows: + // The format for declaring a list is // List = new List(); List intList = new List(); List stringList = new List(); @@ -182,14 +182,14 @@ on a new line! ""Wow!"", the masses cried"; // Lists don't default to a value; // A value must be added before accessing the index intList.Add(1); - Console.WriteLine("intList @ 0: " + intList[0]); + Console.WriteLine("intList at 0: " + intList[0]); - // Others data structures to check out: + // Other data structures to check out: // Stack/Queue // Dictionary (an implementation of a hash map) // HashSet // Read-only Collections - // Tuple (.Net 4+) + // Tuple (.NET 4+) /////////////////////////////////////// // Operators @@ -222,20 +222,20 @@ on a new line! ""Wow!"", the masses cried"; | Bitwise inclusive OR */ - // Incrementations + // Incrementing int i = 0; - Console.WriteLine("\n->Inc/Dec-rementation"); - Console.WriteLine(i++); //Prints "0", i = 1. Post-Incrementation - Console.WriteLine(++i); //Prints "2", i = 2. Pre-Incrementation - Console.WriteLine(i--); //Prints "2", i = 1. Post-Decrementation - Console.WriteLine(--i); //Prints "0", i = 0. Pre-Decrementation + Console.WriteLine("\n->Inc/Dec-rement"); + Console.WriteLine(i++); //Prints "0", i = 1. Post-Increment + Console.WriteLine(++i); //Prints "2", i = 2. Pre-Increment + Console.WriteLine(i--); //Prints "2", i = 1. Post-Decrement + Console.WriteLine(--i); //Prints "0", i = 0. Pre-Decrement /////////////////////////////////////// // Control Structures /////////////////////////////////////// Console.WriteLine("\n->Control Structures"); - // If statements are c-like + // If statements are C-like int j = 10; if (j == 10) { @@ -288,7 +288,7 @@ on a new line! ""Wow!"", the masses cried"; // For Each Loop // foreach loop structure => foreach( in ) // The foreach loop loops over any object implementing IEnumerable or IEnumerable - // All the collection types (Array, List, Dictionary...) in the .Net framework + // All the collection types (Array, List, Dictionary...) in the .NET framework // implement one or both of these interfaces. // (The ToCharArray() could be removed, because a string also implements IEnumerable) foreach (char character in "Hello World".ToCharArray()) @@ -297,7 +297,7 @@ on a new line! ""Wow!"", the masses cried"; } // Switch Case - // A switch works with the byte, short, char, and int data types. + // A switch works with byte, short, char, and int data types. // It also works with enumerated types (discussed in Enum Types), // the String class, and a few special classes that wrap // primitive types: Character, Byte, Short, and Integer. @@ -316,7 +316,7 @@ on a new line! ""Wow!"", the masses cried"; break; // You can assign more than one case to an action // But you can't add an action without a break before another case - // (if you want to do this, you would have to explicitly add a goto case x + // (if you want to do this, you would have to explicitly add a goto case x) case 6: case 7: case 8: @@ -337,14 +337,14 @@ on a new line! ""Wow!"", the masses cried"; // this will throw a FormatException on failure int.Parse("123"); // returns an integer version of "123" - // try parse will default to type default on failure - // in this case: 0 + // TryParse will default to the type's default value on failure + // in this case 0 int tryInt; if (int.TryParse("123", out tryInt)) // Function is boolean Console.WriteLine(tryInt); // 123 // Convert Integer To String - // Convert class has a number of methods to facilitate conversions + // The Convert class has a number of methods to facilitate conversions // String to int @@ -388,7 +388,7 @@ on a new line! ""Wow!"", the masses cried"; Console.Read(); } // End main method - // Available in C# 9 and later, this is basically a syntactic sugar for a class. Records are immutable*. + // Available in C# 9 and later, this is basically syntactic sugar for a class. Records are immutable*. public record ARecord(string Csharp); // CONSOLE ENTRY - A console application must have a main method as an entry point @@ -428,7 +428,7 @@ on a new line! ""Wow!"", the masses cried"; // GENERICS // The classes for TKey and TValue is specified by the user calling this function. - // This method emulates the SetDefault of Python + // This method emulates Python's dict.setdefault() public static TValue SetDefault( IDictionary dictionary, TKey key, -- cgit v1.2.3