为类中的变量分配ApplyingSize [英] Assigning applyingsize to variables in a class

查看:65
本文介绍了为类中的变量分配ApplyingSize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要定义一个类(下面的示例),其中定义的每个变量都必须具有预定义的大小,以便在使用该变量为其提供值时进行设置;我要确保我分配的值不大于其预定义的大小,并且如果分配的值小于最大长度/大小,那么我想用空格填充变量,我该怎么做?提前谢谢.

//使用StringLength属性并不能解决问题(我想我在这里错误地使用了它).

I need to define a class (example below), where each variable defined must have a pre defined size so that when I use that variable to feed it a value; I want to make sure I do not assign a value larger than its pre defined size, and if the value assigned is smaller than the max length/size then I want to pad the variable with spaces, how do I do that? Thanks in advance.

// Using StringLength attribute did not do the trick (I think I am using it wrongly here).

public class FormActivityDetails
{
    [Required]
    [StringLength(10)]
    public string CustomerID { get; set; }
    [Required]
    [StringLength(10)]
    public string DcID { get; set; }
    public string DcIDQual { get; set; }


}

推荐答案

使用具有定义的开始位置和结束位置的子字符串解决.
solved by using substring with defined start location and end location.


这篇关于为类中的变量分配ApplyingSize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆