C
C#2mo ago
Faker

✅ 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
spit on that Thang CHO BOC
no what you essentially did was compress 2 statements into one line (normal C behaviour) int monsterHealth; int heroHealth = 0;
Faker
FakerOP2mo ago
in C it would have work ?
spit on that Thang CHO BOC
C# is friendlier C++ with OP yes
Faker
FakerOP2mo ago
c++ is also C with oop, no? :c
Faker
FakerOP2mo ago
oh ok what's the difference between c++ and C# then pls (I know this isn't the subject of discussion, sorryy :C)
spit on that Thang CHO BOC
depends on what you like or what you prefer (CPP is usually faster) syntax is different too
Faker
FakerOP2mo ago
Ah I see
spit on that Thang CHO BOC
but if you program like normal C in CPP it will still work
Faker
FakerOP2mo ago
yeah got it, thanks !!
ero
ero2mo ago
This is so insanely wrong
spit on that Thang CHO BOC
yeah i see that too now i mean like objects and initializers constructors...
Faker
FakerOP2mo ago
what makes C# different from C then pls
ero
ero2mo ago
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
spit on that Thang CHO BOC
C++ can be used like C C# can't i see it now
ero
ero2mo ago
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)
Faker
FakerOP2mo ago
yep noted, thanks !
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Thalnos
Thalnos2mo ago
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
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Thalnos
Thalnos2mo ago
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
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Faker
FakerOP2mo ago
Yeah true, I will first experiment then ask now

Did you find this page helpful?