Tiny way to get the first 25 characters

后端 未结 12 1593
感动是毒
感动是毒 2020-12-29 13:12

Can anyone think of a nicer way to do the following:

public string ShortDescription
{
    get { return this.Description.Length <= 25 ? this.Description :          


        
12条回答
  •  感动是毒
    2020-12-29 14:12

    public static Take(this string s, int i)
    {
        if(s.Length <= i)
            return s
        else
            return s.Substring(0, i) + "..."
    }
    
    public string ShortDescription
    {
        get { return this.Description.Take(25); }
    }
    

提交回复
热议问题