how to set compile time validation on class instance members

前端 未结 2 1076
Happy的楠姐
Happy的楠姐 2021-01-21 12:32

I have created a class like below:

class myclass
{
  Public  int myint;
}

Now I want to restrict the range of myint(min 5 and max 10).

2条回答
  •  滥情空心
    2021-01-21 13:00

    It's experimental, but you could look into Spec#. It can provide you with more compile-time checks. Code Contracts are another option (but that's only available in certain editions of Visual Studio).

    Edit:

    Looks like code contacts may now be available as a standalone download! See this page!

提交回复
热议问题