✅ Declaring and initializing multiple values in a single line in C#
Hello guys, consider the following statement:
int monsterHealth, heroHealth = 0;
If I write this code, heroHealth is assigned to 0, will this also assign monsterHealth to 0?23 Replies
no what you essentially did was compress 2 statements into one line (normal C behaviour)
int monsterHealth;
int heroHealth = 0;
in C it would have work ?
C# is friendlier C++ with OP
yes
c++ is also C with oop, no? :c
yep
oh ok
what's the difference between c++ and C# then pls (I know this isn't the subject of discussion, sorryy :C)
depends on what you like or what you prefer (CPP is usually faster)
syntax is different too
Ah I see
but if you program like normal C in CPP
it will still work
yeah got it, thanks !!
This is so insanely wrong
yeah i see that too now
i mean like objects and initializers constructors...
what makes C# different from C then pls
A huge amount of C syntax won't work in C#
C and C++ don't have a GC
A lot of the principles that might apply in C don't apply in C#
It's a completely different concept
C++ can be used like C
C# can't i see it now
Taking the code from the OP, using
monsterHealth
later would work fine in C. In C#, using that variable will report a compile time error (use of uninitialized variable)yep noted, thanks !
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
think of c++ as being a higher level version of c. Its was created to make it easier to work with.
Think of c# or java as a higher level version of c++. It was also created to be easier to work with
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
they added concepts that make working with the language easier. For example c# adds a garbage collector to avoid the manual memory management of c++, interfaces instead of multiple inheritance to avoid errors of c++, and other concepts that make it easier to work with the language
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
Yeah true, I will first experiment then ask now