Am I Learning C# Correctly After Four Days?

0
1
Asked By MellowPine42 On

I've been learning C# for about four days and wrote this small health-point example. The method changes hp by a given amount, and if health reaches zero it calls Banish(), which sets hp to zero:

int hp = 10000;

public void HpChange(int howMuch)
{
hp += howMuch;

if (hp <= 0)
{
Banish();
}
else
{
hp = hp;
}
}

public void Banish()
{
hp = 0;
}

I'm still typing on a phone, so apologies for formatting issues. Is this reasonable for someone four days into learning? Is programming mostly about carefully getting lots of small details right, and what are some effective ways to learn faster?

2 Answers

Answered By RiverNook18 On

Programming does involve being precise, but it’s not just about punctuation. Focus on understanding what each line does and practice by building tiny programs you can test. For this example, try different positive, negative, and zero values for `howMuch` and check whether the result matches what you expect. A keyboard would make writing and formatting code much easier, although you can still study concepts on a phone for now.

MellowPine42 -

I don’t currently have access to a keyboard, but I’ll keep practicing with small examples and testing different inputs.

Answered By CopperLark7 On

For four days in, this is a perfectly reasonable exercise. You’re using a variable, a method parameter, arithmetic, and an if statement. The `else` block doesn’t do anything, though—`hp = hp` leaves the value unchanged, so you can remove it. Also, C# is normally pronounced “C-sharp,” even though the symbol is often called a hash in other contexts.

MellowPine42 -

I’ve mostly been learning by reading, and I’ve always thought of # as hash. I’ll try to get used to the usual pronunciation.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.