Skip to content
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

[API Proposal]: Convenient integers reading #74489

Closed
vorotynsky opened this issue Aug 24, 2022 · 4 comments
Closed

[API Proposal]: Convenient integers reading #74489

vorotynsky opened this issue Aug 24, 2022 · 4 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.IO needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Milestone

Comments

@vorotynsky
Copy link

vorotynsky commented Aug 24, 2022

Background and motivation

C# doesn't have an API to read rows of integers from the console nicely.

One of the solutions is:

var array = Console.ReadLine()!.Split(' ', StringSplitOptions.RemoveEmptyEntries);
array = Array.ConvertAll(array, Int32.Parse);

Such a code is necessary for solving problems at codeforces or olympiads.

API Proposal

namespace System.IO;

public static class ReaderExtensions
{
    public static Int32 ReadInt32(this TextReader reader) { throw null; }

    // methods for other types
}

API Usage

var array = new int[10];

for (var i = 0; i < 10; i++)
    array[i] = Console.In.ReadInt32();

Alternative Designs

C++ operators

int arr[10];

for (int i = 0; i < 10; i++)
    std::cin >> arr[i];

Java's Scanner

Scanner scanner = new Scanner(System.in);
int[] arr = new int[10];

for (int i = 0; i < 10; i++)
    arr[i] = scanner.nextInt();

Text format

C has function scanf, and F#, Go has the same API.

C# can adopt it like this:

Console.In.Scanf("%i", ref arr[i]);

Just read a word

for (int i = 0; i < 10; i++)
    arr[i] = Int32.Parse(Console.ReadWord());

Risks

No response

@vorotynsky vorotynsky added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Aug 24, 2022
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Aug 24, 2022
@ghost
Copy link

ghost commented Aug 24, 2022

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

Background and motivation

C# doesn't have an API to read rows of integers from the console nicely.

One of the solutions is:

var array = Console.ReadLine()!.Split(' ', StringSplitOptions.RemoveEmptyEntries);
array = Array.ConvertAll(array, Int32.Parse);

Such a code is necessary for solving problems at codeforces or olympiads.

API Proposal

namespace System.IO;

public static class ReaderExtensions
{
    public static Int32 ReadInt32(this TextReader reader) { throw null; }

    // methods for other types
}

API Usage

var array = new int[10];

for (var i = 0; i < 10; i++)
    array[i] = Console.In.ReadInt32();

Alternative Designs

C++ operators

int arr[10];

for (int i = 0; i < 10; i++)
    std::cin >> arr[i];

Java's Scanner

Scanner scanner = new Scanner(System.in);
int[] arr = new int[10];

for (int i = 0; i < 10; i++)
    arr[i] = scanner.nextInt();

Text format

C has function scanf, and F#, Go has the same API.

C# can adopt it like this:

Console.In.Scanf("%i", ref arr[i]);

Just read a word

for (int i = 0; i < 10; i++)
    arr[i] = Int32.Parse(Console.ReadWord());

Risks

No response

Author: vorotynsky
Assignees: -
Labels:

api-suggestion, area-System.IO, untriaged

Milestone: -

@svick
Copy link
Contributor

svick commented Aug 24, 2022

Related: #64621, which proposes a different API with the same goal.

@jeffhandley jeffhandley added this to the Future milestone Sep 16, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Sep 16, 2022
@jeffhandley jeffhandley added the needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration label Sep 16, 2022
@adamsitnik
Copy link
Member

Hi @vorotynsky

Thank you for your proposal. Since #64621 was opened first and includes proposal for other types as well I am going to close this issue as a duplicate. Please follow #64621 for updates.

@adamsitnik adamsitnik closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.IO needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Projects
None yet
Development

No branches or pull requests

5 participants