From 69f41a89342d78b33679dd22596cad660b7ff9c0 Mon Sep 17 00:00:00 2001 From: Olabamiji Oyetubo <60369677+bigboybamo@users.noreply.github.com> Date: Tue, 11 Jun 2024 23:36:22 +0100 Subject: [PATCH 1/3] Update access-modifiers.md Added description for file access type modifier --- .../programming-guide/classes-and-structs/access-modifiers.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/csharp/programming-guide/classes-and-structs/access-modifiers.md b/docs/csharp/programming-guide/classes-and-structs/access-modifiers.md index 5543714e1a752..2fc42d93fb2ac 100644 --- a/docs/csharp/programming-guide/classes-and-structs/access-modifiers.md +++ b/docs/csharp/programming-guide/classes-and-structs/access-modifiers.md @@ -73,6 +73,8 @@ To set the access level for a `class` or `struct` member, add the appropriate ke Finalizers can't have accessibility modifiers. Members of an `enum` type are always `public`, and no access modifiers can be applied. +The `file` access modifier is allowed only on top-level (non-nested) type declarations. + ## C# language specification [!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)] From f1213b8a784c73ddffa49cff33de2a2504b5c46b Mon Sep 17 00:00:00 2001 From: Olabamiji Oyetubo <60369677+bigboybamo@users.noreply.github.com> Date: Tue, 2 Jul 2024 23:01:28 +0100 Subject: [PATCH 2/3] Update return44.cs Update Code Snippet for Return statement --- docs/csharp/snippets/methods/return44.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/csharp/snippets/methods/return44.cs b/docs/csharp/snippets/methods/return44.cs index 5643f9a14cdaa..76b61dfaf9681 100644 --- a/docs/csharp/snippets/methods/return44.cs +++ b/docs/csharp/snippets/methods/return44.cs @@ -1,4 +1,14 @@ -// +// +class SimpleMathExtnsion +{ + public int DivideTwoNumbers(int number1, int number2) + { + return number1 / number2; + } +} +// + +// class SimpleMath { public int AddTwoNumbers(int number1, int number2) => @@ -14,6 +24,7 @@ static class TestSimpleMath static void Main() { var obj = new SimpleMath(); + var obj2 = new SimpleMathExtnsion(); // int result = obj.AddTwoNumbers(1, 2); @@ -27,5 +38,11 @@ static void Main() // The result is 9. Console.WriteLine(result); // + + // + result = obj2.DivideTwoNumbers(6,2); + // The result is 3. + Console.WriteLine(result); + // } } From 611710f5cd5105445ff95de9a9d6cb6ae7c94141 Mon Sep 17 00:00:00 2001 From: Olabamiji Oyetubo <60369677+bigboybamo@users.noreply.github.com> Date: Tue, 2 Jul 2024 23:08:57 +0100 Subject: [PATCH 3/3] Update methods.md -Add Method example with return statement - Explain expression bodied members --- docs/csharp/methods.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/csharp/methods.md b/docs/csharp/methods.md index 4260f1975472f..313194768775f 100644 --- a/docs/csharp/methods.md +++ b/docs/csharp/methods.md @@ -157,12 +157,20 @@ For example, these two methods use the `return` keyword to return integers: :::code language="csharp" source="snippets/methods/return44.cs" id="snippet44"::: -To use a value returned from a method, the calling method can use the method call itself anywhere a value of the same type would be sufficient. You can also assign the return value to a variable. For example, the following two code examples accomplish the same goal: +The examples above are expression bodied members. Expression bodied members return the value returned by the expression. + +You can also choose to define your methods with a statement body and a `return` statement: + +:::code language="csharp" source="snippets/methods/return44.cs" id="snippet43"::: + +To use a value returned from a method, the calling method can use the method call itself anywhere a value of the same type would be sufficient. You can also assign the return value to a variable. For example, the following three code examples accomplish the same goal: :::code language="csharp" source="snippets/methods/return44.cs" id="snippet45"::: :::code language="csharp" source="snippets/methods/return44.cs" id="snippet46"::: +:::code language="csharp" source="snippets/methods/return44.cs" id="snippet47"::: + Sometimes, you want your method to return more than a single value. You use *tuple types* and *tuple literals* to return multiple values. The tuple type defines the data types of the tuple's elements. Tuple literals provide the actual values of the returned tuple. In the following example, `(string, string, string, int)` defines the tuple type returned by the `GetPersonalInfo` method. The expression `(per.FirstName, per.MiddleName, per.LastName, per.Age)` is the tuple literal; the method returns the first, middle, and family name, along with the age, of a `PersonInfo` object. ```csharp