Why does C# not define an addition operation for char's?

后端 未结 6 956
感动是毒
感动是毒 2020-12-11 04:07

As the title says. Related to this question.

Why does the following code not work? It seems reasonable logically.

string foo = \'a\' + \'b\'; // Fail         


        
6条回答
  •  醉话见心
    2020-12-11 04:36

    What you are really looking for is this:

    string foo = String.Concat('a', 'b');
    

    Which is what the compiler does with the '+' operator on strings anyways.

    This is about twice as fast as any String.Format operation.

提交回复
热议问题