dotnet-api-docs icon indicating copy to clipboard operation
dotnet-api-docs copied to clipboard

string.IsNullOrEmpty() vs. String.IsNullOrEmpty()

Open abergquist opened this issue 1 year ago • 11 comments

When we specify String.IsNullOrEmpty() in our code, Visual Studio recommends that we lowercase the 'S' - hence string.IsNullOrEmpty().

abergquist avatar Jul 09 '24 17:07 abergquist

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 avatar Jul 09 '24 17:07 ghost

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 avatar Jul 09 '24 17:07 ghost

I am unable to add a Documentation area label.

abergquist avatar Jul 09 '24 17:07 abergquist

For some background see string vs. String is not a style debate.

Does your concern belong to an url in the docs? If so, can you please point to that url, so an action could be taken here.

gfoidl avatar Jul 10 '24 13:07 gfoidl

Thanks, @gfoidl.

https://learn.microsoft.com/en-us/dotnet/api/system.string.isnullorempty?view=net-8.0 indicates that we should call String.IsNullorEmpty(); in response, it should indicate that we should call string.IsNullorEmpty() instead.

abergquist avatar Jul 11 '24 04:07 abergquist

IMO the docs are correct, as that's a method of System.String type which is unambiguous. Similar to other members of that type.

In your user code due to the using System the identifier String isn't unambiguous (see blog post), thus the keyword string should be used. This doesn't apply to the API docs though.

Besides that String <-> string is a C# concern, not pure API docs.

But I don't say that there could be some indication to use string on all string members (and similar to object, etc.) if there's a good way to do so w/o bloating the API docs (maybe this belongs to C# docs?).

gfoidl avatar Jul 11 '24 16:07 gfoidl

I'm always up for any (additional) information to help us.

abergquist avatar Jul 11 '24 16:07 abergquist

Tagging subscribers to this area: @dotnet/area-system-runtime

This doesn't apply to the API docs though

While it is less ambiguous for the docs, it would still be generally good if docs were consistent with the default/recommended styling considerations as most readers will view them as code they could/should write themselves, not as something that is specific to the type it's written for.

CC. @gewarren, is there an easy way to audit the doc examples and ensure that for C# we're using the keyword (string, int, long, etc) rather than the type name (String, Int32, Int64, etc)?

tannergooding avatar Jul 25 '24 00:07 tannergooding

Seems like there should be an easy way, what with AI. I've assigned this issue to myself for next month.

gewarren avatar Jul 25 '24 20:07 gewarren

Related to dotnet/docs#41315.

gewarren avatar Aug 01 '24 18:08 gewarren