dotnet / dotnet/dotnet-api-docs
Samples for Byte.CompareTo wouldn't work using the current snippets
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
When looking at the full source code of the C# examples [here](https://github.com/dotnet/dotnet-api-docs/blob/049dcaabd31db9ea06d9854d64813d6e4b5cb1e9/snippets/csharp/System/Byte/CompareTo/systembyte.cs), it's clear that the snippets are meant to be run as part of an instantiated class, with declared class members. In fact, the source code includes a comment stating that `// MemberByte is assumed to exist as a class member.`
However the section included in the `//` tag omits that comment, thereby [displaying sample code](https://github.com/dotnet/dotnet-api-docs/blob/049dcaabd31db9ea06d9854d64813d6e4b5cb1e9/xml/System/Byte.xml) that will not compile, without explanation for where the `MemberByte` field/variable was declared.
I see two obvious ways to potentially fix this (if we agree it's an issue as-is):
1. Move the tag up to include the comment explaining where MemberByte is declared
2. Simply declare a new variable and set that as the result of casting `numberToSet` instead of using the class member
Personally, I think **option 2** is much clearer, and allows each function to demonstrate its capabilities without external dependencies. I don't see a specific reason MemberByte needs to exist, or why these functions couldn't all just be static methods -- removing all interaction between them altogether.
This issue affects the samples written in:
- [C++](https://github.com/dotnet/dotnet-api-docs/blob/049dcaabd31db9ea06d9854d64813d6e4b5cb1e9/snippets/cpp/VS_Snippets_CLR_System/system.Byte%20Examples/CPP/systembyte.cpp)
- [VisualBasic](https://github.com/dotnet/dotnet-api-docs/blob/049dcaabd31db9ea06d9854d64813d6e4b5cb1e9/snippets/visualbasic/VS_Snippets_CLR_System/system.Byte%20Examples/VB/systembyte.vb)
- [C#](https://github.com/dotnet/dotnet-api-docs/blob/049dcaabd31db9ea06d9854d64813d6e4b5cb1e9/snippets/csharp/System/Byte/CompareTo/systembyte.cs)
Contributor guide
Assessment
This issue has not been assessed yet.