I’ve spent the majority of my time this weekend learning the finer points of design in C#, and I have to say that I’m quite impressed.
See, I’m a BASIC developer — or have been since QuickBasic — so I was looking at C# like it was the devil. Pure evil. Ugh. C-Based nonsense. With a little pushing from friends, I decided to give it a go and see where I ended up.
It’s hard to compare C# to any of the BASIC variants I’m used to, but I’m going to try.
Variables
This is a change up that I had a tiny bit of trouble adjusting to. In C#(and any other C style language), there’s no “Dim X As (Type)”. Instead, you simply have the Type name, Variable name, then any assignments. For instance:
int XPosition = 100;Not too bad. “int” is our type, “XPosition” is our variable name, and “100″ is the value we’re assigning to it.
Methods
This one isn’t too different. Instead of like I’m used to in BASIC, having the method definition look like Scope Name(Parameters) As Type, C# moves one thing. It’s Scope Type Name(Parameters). If your method isn’t going to be returning a value? Easy, your type is “void”.
private void myMethod(string myName)
{
}Easy to grasp, right?
Events
Events aren’t as tough to figure out as I thought they’d be. Visual Studio holds your hand the entire way. Start by checking out the “Events” tab of the Property listbox, then go to the language ref and check out what EventArgs etc you need. After that, you simply code up the event, something like…
private void myControl_Paint(object Sender, PaintEventArgs e)
{
}Then go right on back to the “Events” tab in the Property listbox, find the event you want to implement, hit the dropdown, and select the event handler you just coded. Pie.
I’ll be sure to write up more of these articles as I learn the language. Wish me luck!