Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: My first ever C# program (nothing too exciting btw)  (Read 1333 times)

0 Members and 1 Guest are viewing this topic.
My first ever C# program (nothing too exciting b...
« on: December 27, 2008, 06:18:14 am »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4849
I decided to learn at least something of C# before I delve back into XNA.
I'm just following a beginner's book.

This is the first program you actually make.
Wouldn't have been that hard except I had to figure out how to change the names and where to put the goddamn code.   I would say I hate having to figure stuff out on my own when it should be in the book, but it really does help me remember where what goes.

The exit button does not do anything yet.

Anywho, just a simple: Get info, display info type program.

BTW: I added what little comments there are.  None are in this part of the book yet(and there is no source code CD...everything is online so I said !@#$% it to the source code >.<).

Logged
  • Super Fan Gamers!
Re: My first ever C# program (nothing too exciti...
« Reply #1 on: December 27, 2008, 02:03:24 pm »
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 4588
Set a character limit on textbox's.

Something you should always think about is reusability. I notice you've got a block for each of the form objects (please excuse the lack of proper terminology). Why not make a class with methods to create or adjust the properties of those objects, instead of countless this.*'s. Imagine if you did this with 50 objects on the form. Imagine the time you'd spend trying to find certain lines of code. I realise you've used a region to segregate sections, that's fine.

Also, I see you have System.Windows.Forms.*; for every line in each block. By including a using statement up the top, you eliminate the need for it.

using System.Windows.Forms; // Include namespace (I'm sure you already had this line)
...
private void InitializeComponent()
{
    this.label1 = new Label(); // We can now remove the namespace from here
...

If someone could improve upon my suggestions feel free.

Good luck.
« Last Edit: December 27, 2008, 04:38:37 pm by AoDC »
Logged
the a o d c
Re: My first ever C# program (nothing too exciti...
« Reply #2 on: December 27, 2008, 04:53:20 pm »
  • (y)(;>.<;)(y)
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3293
AoDC, just a note. Some people deliberately avoid the use of 'using'. I, for example, do this in C++. It helps avoid some obscurity, confusion and general problems when the same name is used by different namespaces, and since has become habit.
Logged
Re: My first ever C# program (nothing too exciti...
« Reply #3 on: December 27, 2008, 04:57:09 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
AoDC, just a note. Some people deliberately avoid the use of 'using'. I, for example, do this in C++. It helps avoid some obscurity, confusion and general problems when the same name is used by different namespaces, and since has become habit.
The "using" directive also completely defeats the whole point of having a namespace. Namely to prevent name clashes.
Logged
Re: My first ever C# program (nothing too exciti...
« Reply #4 on: December 27, 2008, 05:19:55 pm »
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 4588
AoDC, just a note. Some people deliberately avoid the use of 'using'. I, for example, do this in C++. It helps avoid some obscurity, confusion and general problems when the same name is used by different namespaces, and since has become habit.
I think since it's a single form application we can make an exception. You're thinking too far ahead ;)
Logged
the a o d c
Re: My first ever C# program (nothing too exciti...
« Reply #5 on: December 27, 2008, 05:35:34 pm »
  • (y)(;>.<;)(y)
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3293
Since when was encouraging bad practices early a good idea? Just means more work explaining why everything they know is wrong later.
Logged
Re: My first ever C# program (nothing too exciti...
« Reply #6 on: December 27, 2008, 05:50:27 pm »
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 4588
Since when was encouraging bad practices early a good idea? Just means more work explaining why everything they know is wrong later.
I never said it was a good idea. I said it can be an exception due to the size of the application. The code would still have other namespaces used directly and there'd be no clashes, and the code would look easier on the eyes, which is important if you're just starting out. This just my opinion and you're welcome to disagree.

He's still going to read your post and make a mental note and keep it in mind while he works.
« Last Edit: December 27, 2008, 05:54:03 pm by AoDC »
Logged
the a o d c
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.655 seconds with 51 queries.