dotnet / dotnet/dotnet-api-docs

Samples for Byte.CompareTo wouldn't work using the current snippets

Open
#9,135 1 comment 0 reactions 0 assignees View on GitHub
area-System.Runtime Pri3 untriaged
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.