Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Tag" strings inside List<>

Tags:

string

c#

list

I have three types of strings which I need to put into single a List in a particular order. By 'three types' I mean that there are three ways of treating a string. I thought of using a struct like this to put in the list:

struct Chunk
{
    public char Type;   // 'A', 'B' or 'C'.
    public string Text;
}

Maybe there's a better way of marking a string with how it should be processed?

like image 628
Mike Roll Avatar asked Mar 05 '26 02:03

Mike Roll


1 Answers

You can use an enum. This will give you Intellisense and error checking.

struct Chunk
{
    public TheType Type;   // 'A', 'B' or 'C'.
    public string Text;
}

enum TheType { A, B, C }
like image 51
ispiro Avatar answered Mar 06 '26 16:03

ispiro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!