Determine if a number falls within a specified set of ranges

后端 未结 8 1468
耶瑟儿~
耶瑟儿~ 2021-02-02 13:45

I\'m looking for a fluent way of determining if a number falls within a specified set of ranges. My current code looks something like this:

int x = 500; // Could         


        
8条回答
  •  佛祖请我去吃肉
    2021-02-02 13:53

    In Pascal (Delphi) you have the following statement:

    if x in [40..80] then
    begin
    end
    

    So if a value x falls in that range you execute your command. I was looking for the C# equivalent to this but can't find something as simple and 'elegant' as this.

    This if in() then statement accepts strings, bytes, etc.

提交回复
热议问题