-
Notifications
You must be signed in to change notification settings - Fork 6k
Make snippets with Span<T> interactive #6318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
It would be really good to make these two examples interactive. But I'm still not able to run them successfully from the topic, @pkulikov, although I am able to run them directly in try.dot.net. @LadyNaggaga, do you have any sense of why that might be? |
|
@rpetrusha indeed, that's a good catch. Thank you. Page under consideration: @LadyNaggaga when I run the following code Span<int> numbers = new int[] { 3, 14, 15, 92, 6 };
foreach (int number in numbers)
{
Console.Write($"{number} ");
}
Console.WriteLine();in the first interactive block of the page (just replaced all the code with the one above), the error messages are the following: Should we create another issue to track this? |
|
@rpetrusha @BillWagner what do you think of the following workaround: public class Program
{
public static void Main()
{
Span<int> numbers = new int[] { 3, 14, 15, 92, 6 };
foreach (int number in numbers)
{
Console.Write($"{number} ");
}
}
}Such snippet runs interactively in docs. If that's a solution for now, I'll updated the code in the samples repo. Pros:
Cons:
@LadyNaggaga if Program/Main are absent, are they generated? And if generated, then |
|
@pkulikov As I understand it, Try.Net by default uses C# scripting. And within scripts, top-level variables are treated as fields, which explains CS8345. Also, you can use I think a good way to handle this would be something similar to what Try.Net already can do when it displays only one |
|
As @svick mentioned something similar to this might be a good idea https://try.dot.net/?workspaceType=nodatime.api&fromGist=8e2ea50af097df663d9c8e19eb8fbf0a&bufferId=TryNodaTime.cs@fragment&canShowGithubPanel=true and use #region to specify the code to display |
|
As you suggested, @pkulikov, I think that the best thing to do here is to include the complete code sample rather than just a region of code, Doing something like linking directly to try.dot.net seems to me to create a confusing experience. Thoughts, @svick, @LadyNaggaga, and @BillWagner? |
|
@svick @LadyNaggaga thank you for the explanation and the example. I've submitted MicrosoftDocs/feedback#489 to track your idea separately. |
|
As for this PR, I'll include the complete Program/Main sample to make the snippet interactive. |
|
I agree with your thoughts @rpetrusha
|
|
@BillWagner @rpetrusha as soon as dotnet/samples#162 is merged, this PR is ready to merge as well. |
|
Closing and reopening to begin new build. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @pkulikov. The code now works in the interactive code runner. I'll merge your PR.
The snippet code runs successfully in try.dot.net; it hasn't before. I assume that means snippets in docs can be interactive again.