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

Cast Char to String. #69

Closed
AdamSpeight2008 opened this issue Jan 25, 2015 · 5 comments
Closed

Cast Char to String. #69

AdamSpeight2008 opened this issue Jan 25, 2015 · 5 comments

Comments

@AdamSpeight2008
Copy link
Contributor

Would it be beneficial to have a Char to be cast-able to a String?
You could think of it as a String of one character in length.

@mikedn
Copy link

mikedn commented Jan 25, 2015

As an implicit conversion? Certainly not, that can lead to unnecessary string allocations.

As an explicit conversion? Maybe, but it's not different from calling ToString() and, at least in my experience, rarely necessary.

@alanfo
Copy link

alanfo commented Feb 8, 2015

In practice, you can do:

"" + c

rather than :

c.ToString()

So I'm not sure that:

(string)c

would be a worthwhile improvement.

However, $c would be a nice shorthand for $"{c}" and it needn't be limited to character expressions.

@paulomorgado
Copy link

You're not implying those are the same thing. Are you?

@alanfo
Copy link

alanfo commented Feb 9, 2015

If I've understood string interpolation correctly, then $"{c}" is the same thing as c.ToString().

If it were considered desirable to have a shorter way of converting a char to a string (rather than use hacks such as "" + c), then I was thinking that $c might be a better proposal than a cast.

It also occurred to me that this syntax needn't be limited to converting character expressions to strings - you could convert other types as well - and could be thought of as a shorthand for $"{c}".

@paulomorgado
Copy link

@alanfo

If I've understood string interpolation correctly, then $"{c}" is the same thing as c.ToString() .

No it isn't.

Have a look at this post: Customizing string interpolation in C# 6

@gafter gafter removed this from the Unknown milestone Apr 20, 2015
@gafter gafter added Question Resolution-Answered The question has been answered and removed Feature Request labels Apr 23, 2015
@gafter gafter closed this as completed Apr 23, 2015
dibarbet added a commit to dibarbet/roslyn that referenced this issue Mar 1, 2023
Include a few more warnings that we have from roslyn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants