C # Stores data in string incorrect practice

It's a good practice to have a line like "name = Gina; postion = HouseMatriarch; id = 1234" to store state data in the application. I know that I could also have a structure, class, or hash table to store this information.

Whether it is acceptable practice to stick to dividing key / value pairs in a database field is for use only where the data type is unknown at design time.

Thank you ... I just try to support good design methods.

+3
source share
13 answers

Yes, storing your data in a string like "name = Gina; postion = HouseMatriarch; id = 1234" is a very bad practice. This data structure must be stored in structures or objects because it is difficult to access, validate, and process data in a row. It will take you a lot longer to write the code to parse your string to get your data than just use the C # language structures.

/ , . , , , . , , ? , , , . -: -)

+25

, , . , , , .

+3

, - escape-. , , :

,

=;

; Name = Yeoi;

, , - . , , , , , , .

+3

, , , ( ) . , , ( ). , .

+3

. , , (, / ).

, XML, . :

<user id="1234">
 <name>Gina</name>
 <postion>HouseMatriarch</position>
</user>

:

  • (/) (, XmlDocument XML-)
  • ( )
  • ( xml). SQL Server ( XML, )
  • XML

. , - , - . : XML , / , , "", " " .. "/" ( ) , .

+3

, , , ​​ JSON.

+1

- , , . .

- , , , , .

-, , , . , , KVP. Sebastian Dietz, , . , , .

+1

, , . , , . .

Red Gate Software , .

+1

, , , - . , . , , , - , :

if(dataStringThing.Substring(26, 4) == SomeIdInStringFormat)

, . , , , . .

, , , , ToString() , . , , .

. .

0

() . , .

- , , (, ), , , .

(, , ), , , - . , , , XML JSON. CSV - (, ), ( "Bobby Tables" ( ) - google , ).

, . ? ( ). , , . , XML , XML-. , , , .

0

, , StringList . , ( ) . - .

0
0

.

, , . , . , , , , . , , .

, , . API ( , ..) - (, HTTP ..), . , . , , , , .

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

, .

, , . , , .

If you control both sides of the communication / transport medium, feel free to optimize. If you do not, make mistakes on the interaction side. Remember that the main difference between the two scenarios is the level of self-description built into the data: interoperability has many, optimization reduces it based on general assumptions. Text data is more understandable, but binary files are faster.

Think about your audience.

0
source

All Articles