C
C#2mo ago
IamMax420

✅ why is the random number not being printed to the console?

No description
41 Replies
IamMax420
IamMax4202mo ago
it's in the main function btw I know I can create the "random1" method inside the previous namespace and everything would be fine but I wanted to learn how to use methods from other namespaces
Angius
Angius2mo ago
For starters, two namespaces usually wouldn't be in the same file But omitting that detail, what actually happens? Does the program crash? Does it do nothing? What happens when you try to print some string instead of that random number, does it get displayed?
IamMax420
IamMax4202mo ago
the number is just not getting displayed but other things work fine
Angius
Angius2mo ago
What happens when you try to print some string instead of that random number, does it get displayed?
IamMax420
IamMax4202mo ago
acutally no, I think it's because I have that extra namespace hmm, weird
Angius
Angius2mo ago
Post the entire code, ideally $code
MODiX
MODiX2mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
IamMax420
IamMax4202mo ago
I think I figured it out, now that I've deleted the second namespace everything works correctly but why can't I have multiple namespaces in a single project?
Angius
Angius2mo ago
You can
canton7
canton72mo ago
Did the second namespace have a class, which had a Main method? We're just guessing unless you post your full code
TilionDC
TilionDC2mo ago
You can. But perhaps put seperate namespaces in seperate files. Its easier to remember if you do a ; after the namespace instead of {}
IamMax420
IamMax4202mo ago
ok wait a sec
Angius
Angius2mo ago
You do have multiple Main() methods, then
canton7
canton72mo ago
And let me guess... It printed the array 1, 2, 3, 4, 5, 6, 7, 8 ,9, but didn't print "The maximum element of the array is"?
IamMax420
IamMax4202mo ago
it did print the max element
canton7
canton72mo ago
Can you copy/paste the full output?
IamMax420
IamMax4202mo ago
1 2 3 4 5 9 6 7 The maximum element of the array is 9 9 squared is 81 1 2 3 4 5 6 7 8 9 228744357
canton7
canton72mo ago
So... That's your random number at the bottom?
IamMax420
IamMax4202mo ago
it now works since I renamed the main function from the second namespace yeah but previously it was not being shown
canton7
canton72mo ago
I, obviously, meant the full output at the point that you claimed it wasn't working
IamMax420
IamMax4202mo ago
well, now it's working
TilionDC
TilionDC2mo ago
lol
canton7
canton72mo ago
I'm trying to understand why it wasn't working, so you can learn something
TilionDC
TilionDC2mo ago
I wanna learn why too. Why else would we try to help if we are just gonna be discarded when it works? @IamMax420
IamMax420
IamMax4202mo ago
It wasn't working because there were two main functions with the same name so I renamed the second function, that's all
canton7
canton72mo ago
But you said it printed everything you pasted above, except the random number at the end? That's not explained by it running the wrong Main method
IamMax420
IamMax4202mo ago
yeah but that was before renaming the function, I just found out that that was the issue
canton7
canton72mo ago
Yes it was the issue, but that doesn't explain what you claimed you saw
IamMax420
IamMax4202mo ago
Idk then, but it did fix the problem
canton7
canton72mo ago
Right, chances are you were actually getting a compiler error when you had two Main methods So your code wasn't compiling, but VS gives you this very unhelpful pop-up asking "Do you want to run the last thing that did compile"
IamMax420
IamMax4202mo ago
yeah, that was it
No description
canton7
canton72mo ago
Right, you see? By digging a bit, we've understood what the actual problem was, and you've learnt to look for compiler errors, and not to tell VS to run whatever the last thing that compiled was
canton7
canton72mo ago
Stack Overflow
How to create a Minimal, Reproducible Example - Help Center
Stack Overflow | The World’s Largest Online Community for Developers
IamMax420
IamMax4202mo ago
are you always so condesceding towards beginners?
jetblacksalvation
you learn to live on
canton7
canton72mo ago
I'm just annoyed that you're making it really hard for people to help you, after you asked for help
jetblacksalvation
in moment it can seem condescending You are young u learn not to take it personal
canton7
canton72mo ago
You posted something which worked fine (but as an image, so I had to re-type the whole thing). It took quite a bit of prodding to get you to share your whole code. Then we tried to get you to explain why it was wrong, but you never really did -- the only details you gave were after you'd fixed it. Then you were actively resistent when we tried to understand why what you'd done had fixed it. This whole thing would have taken 1-2 mins if you've have included your full code and its output in the question Anyway, sorry for being short. Glad it's working!
IamMax420
IamMax4202mo ago
thanks for help, have a good day
Want results from more Discord servers?
Add your server
More Posts