Tiny way to get the first 25 characters

后端 未结 12 1569
感动是毒
感动是毒 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:10

    The way you've done it seems fine to me, with the exception that I would use the magic number 25, I'd have that as a constant.

    Do you really want to store this in your bean though? Presumably this is for display somewhere, so your renderer should be the thing doing the truncating instead of the data object

提交回复
热议问题