小编Duk*_*ets的帖子

获得前25个字符的微小方法

任何人都可以想到一个更好的方法来做到以下几点:

public string ShortDescription
{
    get { return this.Description.Length <= 25 ? this.Description : this.Description.Substring(0, 25) + "..."; }
}
Run Code Online (Sandbox Code Playgroud)

我本来希望只做string.Substring(0,25),但如果字符串小于提供的长度,它会引发异常.

c# string

10
推荐指数
4
解决办法
2591
查看次数

标签 统计

c# ×1

string ×1