Skip to content

Commit

Permalink
add example where a type parameter is used a return type (dotnet#40188)
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver authored Mar 26, 2024
1 parent 887aae3 commit 1b9821b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/csharp/programming-guide/generics/generic-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class GenericList2<T>

[!code-csharp[csProgGuideGenerics#28](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csProgGuideGenerics/CS/Generics.cs#28)]

You can also use the type parameter as the return type of a method. The following code example shows a method that returns an array of type `T`:

[!code-csharp[csProgGuideGenerics#29](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csProgGuideGenerics/CS/Generics.cs#29)]

## C# Language Specification

For more information, see the [C# Language Specification](~/_csharpstandard/standard/classes.md#156-methods).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,16 @@ void DoWork<T>() { }
void DoWork<T, U>() { }
//</Snippet28>
}

class Test3
{
//<Snippet29>
T[] Swap<T>(T a, T b)
{
return [b, a];
}
//</Snippet29>
}
}

//---------------------------------------------------------------------------
Expand Down

0 comments on commit 1b9821b

Please sign in to comment.