Redundant Call to Object.ToString()

本文详细解析了C#中使用+操作符进行字符串相加的过程,包括底层如何将整数转换为字符串并调用ToString()方法,以及字符串连接的实际实现方式。通过示例代码展示了编译器如何优化此操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Redundant Call to Object.ToString()

The + operator for string is overloaded to call String.Concat passing in the left and right side of the expression. Thus:

string x = "123" + 45;

Gets compiled to:

String.Concat("123", 45);

Since String.Concat takes in two objects, the right hand side (45) is boxed and then ToString() is called on it.

Note that this "overloading" is not via operator overloading in the language (aka it's not a method named op_Addition) but is handled by the compiler.

转载于:https://www.cnblogs.com/chucklu/p/4754262.html

项目创建后有如下错误: AndroidManifest.xml文件的错误: 无法解析符号 '@style/Theme.FloatingSearchApp' READ_EXTERNAL_STORAGE is deprecated (and is not granted) when targeting Android 13+. If you need to query or interact with MediaStore or media files on the shared storage, you should instead use one or more new storage permissions: `READ_MEDIA_IMAGES`, `READ_MEDIA_VIDEO` or `READ_MEDIA_AUDIO`. Redundant label can be removed DatabaseHelper.kt文件的错误: 应为 <database name> 或 <defined table name>,得到 '$' Value must be ≥ 0 but `getColumnIndex` can be -1 Parameter 'question' is never used FloatingWindowService.kt文件的错误: Avoid passing `null` as the view root (needed to resolve layout parameters on the inflated layout's root element) 'TYPE_PHONE: Int' is deprecated. Deprecated in Java `onTouch` should call `View#performClick` when a click is detected Do not concatenate text displayed with `setText`. Use resource string with placeholders. String literal in `setText` can not be translated. Use Android resources instead. Variable 'answer' is never used Do not concatenate text displayed with `setText`. Use resource string with placeholders. String literal in `setText` can not be translated. Use Android resources instead. MainActivity.kt文件的错误: Unresolved reference: activity_main This declaration overrides deprecated member but not marked as deprecated itself. Please add @Deprecated annotation or suppress. See https://youtrack.jetbrains.com/issue/KT-47902 for details TextRecognizer.kt文件的错误: No value passed for parameter 'options' 'getter for defaultDisplay: Display!' is deprecated. Deprecated in Java 'getMetrics(DisplayMetrics!): Unit' is deprecated. Deprecated in Java Parameter 'context' is never used floating_window.xml文件的错误: Hardcoded string "问题将显示在这里", should use `@string` resource Hardcoded string "答案将显示在这里", should use `@string` resource
最新发布
06-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值