• 0

I'm too stupid to understand C#


Question

I started reading hfcsharp a few days back; everything was going smoothly until I reached my lab program "A day at the Race".

I read through the problem in the book, and did not know where to start from, so I went directly to the hfc# website page and downloaded the solution. The solution was perfect, with no errors; but I was unable to understand some lines in the code. The book did a poor job of explaining this, to me, and I have read through the book twice looking for a solution. I found nothing reliable to compare and understand from, though I did look through some questions about the same lab program; most were too complicated for me to understand. The question list was pretty big, so i made a PDF pointing to which parts I didn't understand, so that you guy can look into it.

I also read threw some similar problem relating to this topic in stack overflow and all the keywords i didn't understand in MSDN docs ,none of them helped in getting the answer that i expected, but instead they  raised more questions.  

I used to code using assemble  language and vhdl before but when never have i coded anything using c++, c or c# i find this very hard to understand it's nothing like assemble language or vhdl please help i'm really interested in learning C# i want to peruse my career in it.

Link to comment
Share on other sites

Recommended Posts

  • 0

 

3 hours ago, Gary7 said:

Assembly Language is very hard at least for me. It takes 50 lines of code for a very simple program..

Can you guys look into my pdf  ?

 

Link to comment
Share on other sites

  • 0

ill take  a quick look but tbvh mate i aint touched C or coding past scripting in almost 15years :p 

 

@adrynalynemay be way more up to date on such things than I, im a hardware guy.

3 hours ago, Gary7 said:

Assembly Language is very hard at least for me. It takes 50 lines of code for a very simple program..

assembler drove me to wanting to jump off a bridge.....what do you mean if i want a keyboard input from the user, i have to tell what lib to use to utilise the keyboard.....gawd man no! :p im getting all nervy and anxious just thinking back to assembly lang.....eeeeeeeeeek!

Link to comment
Share on other sites

  • 0
3 hours ago, Gary7 said:

Assembly Language is very hard at least for me. It takes 50 lines of code for a very simple program..

LOL  that's exactly what i thought when i read assembly...  i took 68000 assembly back in college, what a waste of time

Link to comment
Share on other sites

  • 0
17 minutes ago, Ch33f said:

 

Can you guys look into my pdf  ?

 

I can later. It's pretty straightforward, you just aren't used to OOP. 

Link to comment
Share on other sites

  • 0

It seems like you're questioning the intricacies and small details rather than the major syntax. You understand the functions and classes etc...

 

For example, there is a string definition, and you ask does this need to be here, and yes you do. You need to define things before (or at the time) of use. Like the Null object near the top, or the empty RANDOM. All that is doing is telling the compiler, "At some point I will use this". Then later on you overwrite it or add to it. 

 

The "this" syntax, is also just one of those things you can accept. There are other ways to instantiate or set properties inside other classes and object, and this is just a way of doing it for this particular one.

 

You ask about the events. At some place on the UI file, it will say "on change of this thing, run this function" and it will go and call the onchange function. Just accept that it's doing it if you can't find the declaration. (YOu can set these programmatically also with objectname.change += functionname

 

Link to comment
Share on other sites

  • 0

well i could point out some things from top to bottom.

 

1. null is there to instantiate the picturebox with no value/image, some controls require either null or an value.

2. random is a internal class in .net and is used to give back random values between one or two values, you're just instantiating your own and calling it myrandom for later use...which you use later (below)

3. int distance is a integer called called distance and it's value will be set randomly between numbers 1-5 , eg: 14532..etc but only between the 1,5.

4. No, the method can be below the code, above it or in another class, once the method is called, it will be found...or not.

5. it's getting the location (number of moves your dog pic has taken and subtracting it back so yes , that is what it's doing.

6. point is a point on your form, which is an X and Y value, so when point is set with these two values, that image will be moved to that point on the form, in this occasion, to the right (X axis).

7. This is called a constructor, it's where you can create a guy object with the other parameters filled with your data, like Guy(bob,mybet.bet1,500,myradiobutton.bob); for example would create a guy with these values using that constructor.

8. this is used to imply it's a value from that class only. you could have two ints called myint but only this.myint would be the one from that class. EG: would be the fact your passed a name string and have a string called name also.

9. you're using another constructor this time but using the bet classes default constructor that takes a amount , dog number and guy object you created earlier, and this because you're calling it still from guy..hence from that class and this.

10.   same as above

11. yes, unless you want every description to stay in that string everytime the methods called.

 

you only need one constructor to make many instances of guy or bet, the constructors are made to take as many different values as you can throw at them, and are reuseable.

 

pardon if this looks all out of place or parts wrong, on my phone...but will give you a lil idea.

Link to comment
Share on other sites

  • 0
41 minutes ago, Buttus said:

LOL  that's exactly what i thought when i read assembly...  i took 68000 assembly back in college, what a waste of time

I did as well, drove me nuts almost.

  • Like 2
Link to comment
Share on other sites

  • 0
1 hour ago, Gary7 said:

I did as well, drove me nuts almost.

me also. year after completing the HND in Computing Support, they took it out the course! lol

Link to comment
Share on other sites

  • 0

I have a firm understanding of Assembly, it's not nearly as bad as you guys claim. I'm quite familiar with C/C++ but C# looks like chicken poop to me. I'll look at it more when I'm not using Cell Data to view everything. Every KB counts :(

Link to comment
Share on other sites

  • 0
3 hours ago, Dermot said:

well i could point out some things from top to bottom.

 

1. null is there to instantiate the picturebox with no value/image, some controls require either null or an value.

2. random is a internal class in .net and is used to give back random values between one or two values, you're just instantiating your own and calling it myrandom for later use...which you use later (below)

3. int distance is a integer called called distance and it's value will be set randomly between numbers 1-5 , eg: 14532..etc but only between the 1,5.

4. No, the method can be below the code, above it or in another class, once the method is called, it will be found...or not.

5. it's getting the location (number of moves your dog pic has taken and subtracting it back so yes , that is what it's doing.

6. point is a point on your form, which is an X and Y value, so when point is set with these two values, that image will be moved to that point on the form, in this occasion, to the right (X axis).

7. This is called a constructor, it's where you can create a guy object with the other parameters filled with your data, like Guy(bob,mybet.bet1,500,myradiobutton.bob); for example would create a guy with these values using that constructor.

8. this is used to imply it's a value from that class only. you could have two ints called myint but only this.myint would be the one from that class. EG: would be the fact your passed a name string and have a string called name also.

9. you're using another constructor this time but using the bet classes default constructor that takes a amount , dog number and guy object you created earlier, and this because you're calling it still from guy..hence from that class and this.

10.   same as above

11. yes, unless you want every description to stay in that string everytime the methods called.

 

you only need one constructor to make many instances of guy or bet, the constructors are made to take as many different values as you can throw at them, and are reuseable.

 

pardon if this looks all out of place or parts wrong, on my phone...but will give you a lil idea.

 

3 hours ago, lunamonkey said:

It seems like you're questioning the intricacies and small details rather than the major syntax. You understand the functions and classes etc...

 

For example, there is a string definition, and you ask does this need to be here, and yes you do. You need to define things before (or at the time) of use. Like the Null object near the top, or the empty RANDOM. All that is doing is telling the compiler, "At some point I will use this". Then later on you overwrite it or add to it. 

 

The "this" syntax, is also just one of those things you can accept. There are other ways to instantiate or set properties inside other classes and object, and this is just a way of doing it for this particular one.

 

You ask about the events. At some place on the UI file, it will say "on change of this thing, run this function" and it will go and call the onchange function. Just accept that it's doing it if you can't find the declaration. (YOu can set these programmatically also with objectname.change += functionname

 

both of your answers helped me carve a path into  understanding on how the program runs, so i dug deeper looking through other research material on this, point and Next yet again ran in to some doubts.

 

1)  Under point there is a line point p =  MypictureBox.location  can this be represented as MypictureBox(location) or MypictureBox.location()

2)  Here MypictureBox is Controlpoint and location is a variable so i have seen in previous programs that Class.method() can be used in a statement to declare a method or while initializing components and as in above code we see Controlpoint. Variable  being used,what other types can be used,can variable.variable be used ?

3) i some code i have seen lines like Size buttonSize = (Size)startPoint; here starting point being the variable like point p being used in this code see here how teh bracket is being sued before a variable i have see this type of line behaviour  while casting an variable  from short to int, my question is what is happening here, can brakets be decalrd befor a variable or a class or a method ?

4)Under form1 (page 2) up on removing Application.DoEvent() line had no effect on the code when compiled same goes for making race.Enabled = false to true

 

When ever i compile my code and press Race! button the execution is instant and the winning dog is revealed right away, is there some line of code that i could ad to modify the animation of picture box go slower ?

Edited by Ch33f
adding some more doubts
Link to comment
Share on other sites

  • 0

You're asking basic syntax questions which leads me to think you're being rushed into an exercise without proper understanding of the language beforehand.

 

Anyway, to answer your questions:

 

What is null doing here? It's a field initializer. It's useless here because fields of reference types (like PictureBox) are default-initialized to null anyway if you don't specify it.

 

There is no class Random created... Yes there is one, it is called System.Random, your project is referencing it via its reference to mscorlib.dll, and you can just write Random rather than System.Random because of that using System; directive at the top of the file.

 

How is next moving PictureBox randomly? Random.Next(a, b) returns a random value comprised between a and b. This value is then passed into a method called MoveMyPictureBox. This function moves the picture box by the amount specified, here a random amount between 1 and 5.

 

Is this method resetting all the dog's picturebox to starting position? It is calling MoveMyPictureBox with -Location and then setting Location to 0. Think about the effect this will have.

 

Point? Point is just an (X, Y) value.

 

What is happening on this line? Nothing, it's a method declaration.

 

No time for the rest, but lots of explanations online about what "this" means.

Link to comment
Share on other sites

  • 0
4 hours ago, Andre S. said:

You're asking basic syntax questions which leads me to think you're being rushed into an exercise without proper understanding of the language beforehand.

 

Anyway, to answer your questions:

 

What is null doing here? It's a field initializer. It's useless here because fields of reference types (like PictureBox) are default-initialized to null anyway if you don't specify it.

 

There is no class Random created... Yes there is one, it is called System.Random, your project is referencing it via its reference to mscorlib.dll, and you can just write Random rather than System.Random because of that using System; directive at the top of the file.

 

How is next moving PictureBox randomly? Random.Next(a, b) returns a random value comprised between a and b. This value is then passed into a method called MoveMyPictureBox. This function moves the picture box by the amount specified, here a random amount between 1 and 5.

 

Is this method resetting all the dog's picturebox to starting position? It is calling MoveMyPictureBox with -Location and then setting Location to 0. Think about the effect this will have.

 

Point? Point is just an (X, Y) value.

 

What is happening on this line? Nothing, it's a method declaration.

 

No time for the rest, but lots of explanations online about what "this" means.

i'm reading from head first C#, the book does a brilliant job of teaching how to program, but a poor job of explaining  basic syntax, however this book is suggested to be read by people like me, People who have no clue about computer enginnering background.

Link to comment
Share on other sites

  • 0
5 hours ago, BinaryData said:

I have a firm understanding of Assembly, it's not nearly as bad as you guys claim. I'm quite familiar with C/C++ but C# looks like chicken poop to me. I'll look at it more when I'm not using Cell Data to view everything. Every KB counts :(

why do you feel C# is trash.

Link to comment
Share on other sites

  • 0
3 minutes ago, adrynalyne said:

I disagree with that assertion as well. 

Here i am trying to learn C# and every where i go most of the programmers recommend me to start with C or learn C++ instead , also in some other forums programmers say that C# makes people stupid; because of the visual studio software that points out every mistake  a coder makes in his program and requires less thinking when coding; 

while other class of people suggest learning C++ before C# develops bad habits and makes the person an inefficient C# programmer.

 

So i decided the easier the software to work with the faster i can finish the task and visual studio did just that thing when i started using it

 

Link to comment
Share on other sites

  • 0
4 minutes ago, Ch33f said:

Here i am trying to learn C# and every where i go most of the programmers recommend me to start with C or learn C++ instead , also in some other forums programmers say that C# makes people stupid; because of the visual studio software that points out every mistake  a coder makes in his program and requires less thinking when coding; 

while other class of people suggest learning C++ before C# develops bad habits and makes the person an inefficient C# programmer.

 

So i decided the easier the software to work with the faster i can finish the task and visual studio did just that thing when i started using it

 

I work in many languages. I don't rely on intellisense at all but it's convenient to have. Sounds like you were listening to elitist developers who think notepad is the only way to develop. If you are concerned with that, use a text editor and compile it via msbuild with a console. C# doesn't make you lazy, laziness makes you lazy. 

Link to comment
Share on other sites

  • 0
25 minutes ago, adrynalyne said:

C# doesn't make you lazy, laziness makes you lazy.

I might put that in my sig. Yea, it's been 12 years since I've done c++/c#. I hated it, but it was a required class in College...

Link to comment
Share on other sites

  • 0

At the end of it all, it really doesn't matter which language you start off with as it always helps when you move to the next one because the syntax may be different but the fundamental core is very similar in most languages. A programmer may find one syntax better than another's and stick with what he likes, it doesn't make it more superior than the next, just more favourable to him/her. C# is not everybodies cup of tea but the language is been updated at a very fast pace and has the benefit of being very similar to java and .net is in the process of being opened up which bodes well for it. Most programmers who suggest learning 'C' or 'C++' didn't have the option of C# or many other new languages so they know no better but to suggest what they learned and more accustomed to, but this shouldn't give you the idea they're the only real choice out there.

Link to comment
Share on other sites

  • 0
10 minutes ago, Dermot said:

At the end of it all, it really doesn't matter which language you start off with as it always helps when you move to the next one because the syntax may be different but the fundamental core is very similar in most languages. A programmer may find one syntax better than another's and stick with what he likes, it doesn't make it more superior than the next, just more favourable to him/her. C# is not everybodies cup of tea but the language is been updated at a very fast pace and has the benefit of being very similar to java and .net is in the process of being opened up which bodes well for it. Most programmers who suggest learning 'C' or 'C++' didn't have the option of C# or many other new languages so they know no better but to suggest what they learned and more accustomed to, but this shouldn't give you the idea they're the only real choice out there.

very good point mate, thats exactly why i suggested C, it was knocking on 15years ago i experienced C/ c++

Link to comment
Share on other sites

  • 0
I disagree with that assertion as well. 

why do you feel C# is trash.

Well, it gives me flashbacks to vb .net and the horrible headaches that language gave me back in the early 2000s. When I was going to ITT-Tech they beat it into our heads that this was a "support" language. Meaning, you build your tools to support your primary application. I was going for multimedia & game development. Iirc, Dopamine is coded in C#. But I've always felt that if you learn any language it should be a cross platform one. C/C++, Python, etc. C# is on its way to being cross platform. Don't even say mono, that project has given me so many headaches.

So, what it boils down to is, just my opinion. I'm used to C++ and controlling every little bit of information.

Sent from my SM-N910V using Tapatalk

Link to comment
Share on other sites

  • 0
12 minutes ago, BinaryData said:

 


Well, it gives me flashbacks to vb .net and the horrible headaches that language gave me back in the early 2000s. When I was going to ITT-Tech they beat it into our heads that this was a "support" language. Meaning, you build your tools to support your primary application. I was going for multimedia & game development. Iirc, Dopamine is coded in C#. But I've always felt that if you learn any language it should be a cross platform one. C/C++, Python, etc. C# is on its way to being cross platform. Don't even say mono, that project has given me so many headaches.

So, what it boils down to is, just my opinion. I'm used to C++ and controlling every little bit of information.

Sent from my SM-N910V using Tapatalk
 

 

C# is nothing like VB.net though. The shared methods between the two is .net specific and not specific to the language.  You shoulnt be learning just one language at any rate because there are different use cases and platforms. Limiting yourself to just cross-platform languages doesn't make a lot of sense if it doesn't fit the use case. 

Link to comment
Share on other sites

This topic is now closed to further replies.