Yrth 18 Newbie Poster

Now, we arrive at the subject of the thread, at last. The question was, "Is that the correct way to save data?" It is the only way to save data. It is the only way to move data. At the end of the day, a hard-disk drive is nothing more spectacular than a very sophisticated, elaborate magnetic tape drive. The material is organized in a different way, there are more heads, and so on, but in terms of how they store data, a cassette tape and a disk drive are identical. The cassette tape and drive are just a lot more primitive than the disk and disk drive.

The real question is, "Is the C# Serialization implementation the correct way to save data? The correct answer is, "It depends."

If you're streaming text data or XML data, then the built-in Text and XML Serialization formatters will save you a lot of work. If you're streaming arbitrary data types, then the Binary formatter will preserve and transmit a lot of information about the data you are transmitting. These are all useful tools, and in many cases will be very useful and time-saving.

If you are, however, saving a fixed data structure of a specific size to a file over and over again, then any of the existing formatters are, at best, a cumbersome and bloated solution to the problem. Whether that disqualifies them as candidates depends on what you are prepared to sacrifice in terms of computing resources …

Murtan commented: Concise, clear and I agree with it +2
Yrth 18 Newbie Poster

Very helpful! At least to me! Thanks! Did you write that or is that from a website? Where can I read the rest of it?

There is no web-site. I wrote that, and that's all there is to it - for now. My other activities keep me tied up most of the time, but when I can find a moment, I like to toss in my two cents.

Most of what I know is synthesized from years of reading and experience, so I can't really even point you at a specific book that would be good to read. I can tell you this, though. C# is a manifestation of a style that is common to C, C++, Java, Javascript, and other languages. If you understand C#, example code in C++ or Java will be clear enough to understand, and those are both object-oriented languages, so if you're looking for books or web-sites, don't get tunnel-vision. The truth does not depend on where you find it.

Yrth 18 Newbie Poster

Scope can be confusing to some. In C or C++, it was useful to think of scope in terms of braces. In C#, this relationship holds, but with some minor but important differences.

First, there are two types of variable. Global and local. In C#, a global variable is called 'static' and is preceded by the 'static' keyword. A static variable is class-specific. That is, if it is public, it can be used as if it were a property of the class. If it is protected, it is accessible as a property of the class, but only to that class and its descendents. If it is private, it is accessible as a property of the class, but only to instances of that class. Thus, a 'public static' variable can be used by anything anywhere in a program, so these are truly global variables in every sense.

In my code, I frequently have a class that I define that specifies all of the data that can be stored in the registy, and how to read it from the registry and write it to the registry. I normally make the only instance of this class a public static variable of the main form object, so that the values can be accessed and/or set from anywhere else in the program. In general, you should constrain your use of static variable to where they are actually necessary and useful. Over-using them constrains the flexibility of your code uneccessarily.

The other type …

Yrth 18 Newbie Poster

Many people have provided answers here, and I do not wish to step on any of this good advice. I just thought I would toss in mine, because it is my opinion that the more different viewpoints you find, the more likely it is that you will find one that makes perfect sense to you.

I learned that in Calculus. They didn't teach that in High School when I was young, but the topic always fascinated me. After reading about a dozen books on the topic, it still made no sense. Most of them were textbooks predicated on the assumption that there was a professor to fill in the blanks. I finally found a book that explained calculus from basic principles, and that was my Eureka. It made perfect sense, to the point where I started kicking myself for not thinking of it myself.

To make things easier, I will put several articles in here, starting with this one, on Objects.

OOP is often thought about as a 'different' programming paradigm. It isn't really. It's the same old paradigm. People (like one example here) like to describe OOP in terms of real world things. I like to describe it in terms that make sense to a programmer, because if you want to know, you are, or aspire to be one.

An object is a data type. Boom. That's the big mystery. That's all it is. It's a user-defined data type. All data types have behaviors that …