41 Replies
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
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?
the number is just not getting displayed
but other things work fine
What happens when you try to print some string instead of that random number, does it get displayed?
I can take the code you've posted, run it, and it works fine: https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwAICYCMBYAUHqAQwFsBTAZwAdCBjUgAgBUALASygHM8BvPe/+qgDMg9IMwB2PgN64B80emkL6slSvbB6YQlDgB7YvQC89KPoDuATwB0qSTZ17DmABQBKANzL1/ewE5XJwNiLx95AF8fKNwYghIKajozSyseH01SMCIAG1FxKTkZcPlhcQA2ek1tXRC3dxLiot8BACVawxq9EzNSC3p252IPb2aWqqgtMB7gmwA5UgAPYBHGlVQJbVGWmMi8CKA
Therefore, the problem must be in part of the code which you haven't shared
acutally no, I think it's because I have that extra namespace
hmm, weird
Post the entire code, ideally
$code
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/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?
You can
Did the second namespace have a class, which had a
Main
method?
We're just guessing unless you post your full codeYou can. But perhaps put seperate namespaces in seperate files.
Its easier to remember if you do a ; after the namespace instead of {}
ok wait a sec
You do have multiple
Main()
methods, thenAnd 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"?
it did print the max element
Can you copy/paste the full output?
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
So... That's your random number at the bottom?
it now works since I renamed the main function from the second namespace
yeah but previously it was not being shown
I, obviously, meant the full output at the point that you claimed it wasn't working
well, now it's working
lol
I'm trying to understand why it wasn't working, so you can learn something
I wanna learn why too. Why else would we try to help if we are just gonna be discarded when it works? @IamMax420
It wasn't working because there were two main functions with the same name
so I renamed the second function, that's all
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
yeah but that was before renaming the function, I just found out that that was the issue
Yes it was the issue, but that doesn't explain what you claimed you saw
Idk then, but it did fix the problem
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"
yeah, that was it
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
Stack Overflow
How to create a Minimal, Reproducible Example - Help Center
Stack Overflow | The World’s Largest Online Community for Developers
are you always so condesceding towards beginners?
you learn to live on
I'm just annoyed that you're making it really hard for people to help you, after you asked for help
in moment it can seem condescending
You are young u learn not to take it personal
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!
thanks for help, have a good day