c# - choosing the right data type and logic storing custom array like records(values) -


say have object, has [id], [name] .. , other data-info call meta , real data (it's value)

x:2 , y:3 l:6, t:5, n:0 ,genr:plate; x:12 , y:32 l:26, t:45, n:1 ,genr:temp; 

..... x 20

what appropriate datatype ?

as don't need store each element in array in it's own row /record use single record.

what choose best practice, string ? byte array ? not in manner of mem consumption performance , elegance

since data type comes in pair

x:2 , y:3 l:6, t:5, n:0 ,genr:plate; x:12 , y:32 l:26, t:45, n:1 ,genr:temp; 

and since value can either number or text, in c#, consider of using dictionary<string, string> store 1 line. thus, if have 20+ lines of such, consider using list of dictionary<string, string>, is:

list<dictionary<string,string>> data = new list<dictionary<string,string>>(); 

to add new data, create dictionary, split items, , add dictionary list:

string line = "x:2 , y:3 l:6, t:5, n:0 ,genr:plate; x:12 , y:32 l:26, t:45, n:1 ,genr:temp;"; dictionary<string,string> linedata = new dictionary<string,string>(); string[] lineitems = line.split(new char[] { ',', ';', ':' }, stringsplitoptions.removeemptyentries); (int = 0; < lineitems.length; += 2)     linedata.add(lineitems[i], lineitems[i + 1]); data.add(linedata); //each line 1 single record in data list 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -