V
V
Vasily Vasilyev2017-10-29 15:45:47
Regular Expressions
Vasily Vasilyev, 2017-10-29 15:45:47

How can enum assign regex "any number" (See description)?

public enum Types{
SomeChar = 'D',
Number = ..//нужно чтобы Number соответствовал любому(!) целому/дробному числу
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Nemiro, 2017-10-29
@Basil_Dev

In enums, only integer values ​​( byte , sbyte , short , ushort , int , uint , long , and ulong ) or char are allowed .
Alternatively, one of the values ​​of an enumeration element may mean that this value must match any number. But to do this, you need to write code that can correctly interpret such a value.
Instead of enums, you can use constants ( const ) or readonlyvariables. In the latter case, the possibilities for using various data types are not limited, unlike constants. You still have to write the code for verification.

G
GavriKos, 2017-10-29
@GavriKos

In enum - no way.

C
cicatrix, 2017-10-30
@cicatrix

Alexei Nemiro absolutely rightly noted that

In enums, only integer values ​​(byte, sbyte, short, ushort, int, uint, long, and ulong) or char are allowed.

But you can cheat by creating a structure or class containing a set of string constants (this doesn’t make much sense for the compiler, but it’s very convenient for code readability and subsequent support):
struct STRING_ENUMERATION
{
    public const string ENUM_A = "Это строка перечисления";
    public const string ENUM_B = "Это другая строка перечисления";
}

class Program
{
    static void Main(string[] args)
    {
        string myVar = STRING_ENUMERATION.ENUM_A;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question