Skip to content

Commit 77739b0

Browse files
authored
Bigboybamo patch 3 (#41636)
* Update access-modifiers.md Added description for file access type modifier * Update return44.cs Update Code Snippet for Return statement * Update methods.md -Add Method example with return statement - Explain expression bodied members
1 parent 3e209a3 commit 77739b0

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

docs/csharp/methods.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,20 @@ For example, these two methods use the `return` keyword to return integers:
157157

158158
:::code language="csharp" source="snippets/methods/return44.cs" id="snippet44":::
159159

160-
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:
160+
The examples above are expression bodied members. Expression bodied members return the value returned by the expression.
161+
162+
You can also choose to define your methods with a statement body and a `return` statement:
163+
164+
:::code language="csharp" source="snippets/methods/return44.cs" id="snippet43":::
165+
166+
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:
161167

162168
:::code language="csharp" source="snippets/methods/return44.cs" id="snippet45":::
163169

164170
:::code language="csharp" source="snippets/methods/return44.cs" id="snippet46":::
165171

172+
:::code language="csharp" source="snippets/methods/return44.cs" id="snippet47":::
173+
166174
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.
167175

168176
```csharp

docs/csharp/snippets/methods/return44.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
//<Snippet44>
1+
//<Snippet43>
2+
class SimpleMathExtnsion
3+
{
4+
public int DivideTwoNumbers(int number1, int number2)
5+
{
6+
return number1 / number2;
7+
}
8+
}
9+
//</Snippet43>
10+
11+
//<Snippet44>
212
class SimpleMath
313
{
414
public int AddTwoNumbers(int number1, int number2) =>
@@ -14,6 +24,7 @@ static class TestSimpleMath
1424
static void Main()
1525
{
1626
var obj = new SimpleMath();
27+
var obj2 = new SimpleMathExtnsion();
1728

1829
//<Snippet45>
1930
int result = obj.AddTwoNumbers(1, 2);
@@ -27,5 +38,11 @@ static void Main()
2738
// The result is 9.
2839
Console.WriteLine(result);
2940
//</Snippet46>
41+
42+
//<Snippet47>
43+
result = obj2.DivideTwoNumbers(6,2);
44+
// The result is 3.
45+
Console.WriteLine(result);
46+
//</Snippet47>
3047
}
3148
}

0 commit comments

Comments
 (0)