Limit string length to property

This question arose when I tried to figure out a big problem, which, for simplicity, I omit.

I have to introduce a specific data structure in C #. Its protocol to be used for communication with an external system. Thus, it has a sequence of strings with predefined lengths and integers (or other, more complex data). Let's pretend that

SYSTEM : four chars
APPLICATION : eight chars
ID : four-byte integer

Now, my preferred way of representing this would be to use strings, therefore

class Message
{
    string System {get; set; };      // four characters only!
    string Application {get; set; }; // eight chars
    int Id {get; set; };
}

Problem: I have to guarantee that the string has no longer a predefined length. In addition, this header will actually have tenths of fields that will change from time to time (we still decide the layout of the message).

​​? , , XML , , ( ).

, , . , /...

+3
1

: . , , "" . , .

: , , (, , , ), , - (, XML), , .

, , , - , , , , , .

+7

Source: https://habr.com/ru/post/1735492/


All Articles