Thursday, February 17, 2011

First C# post

Want me to be honest? I have no clue if this blog setup will work with the coding i'm going to be doing, hell, i don't even think they have code tags, so ill prolly use the quotes :P

Ok, so C#, Its one of the easier to learn languages, it follows a pretty simple pattern. One of the harder things to learn about c# is Object Oriented Programming. Its somewhat hard to explain, but lets say you have a Mixed case of soda. And each can of soda is of a different Brand and Flavor. In c# and other object oriented languages, you can make what are called "objects", an object being a reference to anything. In this case the cans of soda. so the object is the box that the sodas are in. An object holds different variables (settings) that can be set for each instance (an instance is, in this case, 1, specific, can of soda).

So far we have A Box, and 12 cans inside that box.
The box represents the object, and the cans represent specific instances of that object.

Inside the object for the cans (each instance) has settings that can be independent from all the other cans. For this analogy were going to give each can two settings, A brand, and a Flavor.

Our analogy now looks something like this:
  • Box
    • Can1
      • Brand
      • Flavor
    • Can2
      • Brand
      • Flavor
    • Etc
So you can see how each can has its own settings. In c# we can access these settings very easily. Assuming that all your names are the same as what we have here, you could simple use Can1.Brand or Can1.Flavor to get the setting that you need for a specific can.


The code is almost just as easy, one way to do it would be to make a list (more on that later) of the cans in the "box", and the code to get the "brand" of the first "can" (Cans is the lists the cans)

Cans[1].Brand


That would give you the brand of the first can in the list. Really, its that easy (That's just accessing the variables, the coding of the Objects itself isn't too hard, nor is actually making the instances.)


You will find that the "hard" part of coding comes in managing large projects, and making everything in a large project work nicely together. Most programmers would agree that the absolute worst thing that can happen while programming (often worse then losing 2-3 hours of code due to a crash or something) is getting an obscure bug that cripples your code. But that cant be replicated 100% of the time. It can take a long time to find something as small as a single character typo (an x to a y for example)




Anyone whom read both of my first posts will realize that i didn't follow suit and write a hello-world tutorial. I thought it was more beneficial if i wrote something to help people grasp the concept of object oriented programming first, though I'm not sure how well I did, I would hope not too bad for a first try.

No comments:

Post a Comment