C
C#•2w ago
77_105_114_111

System.Console

Hi, Is good practice to use System.Console.WriteLine(); instead of declaring the System library outside of main?
10 Replies
Pobiega
Pobiega•2w ago
no using System; is your friend
FusedQyou
FusedQyou•2w ago
I see no reason why you would define the whole namespace of an object. It makes it very unreadable. The only real reason would be ambiguity between two classes, in which case you'd be able to define an alias or define specifically what class to use at the top with an using statement. Always at the top of the file.
77_105_114_111
77_105_114_111OP•2w ago
using namespace std; in C++ can cause some bugs later on the track that way its best practice to not use namespace std; but to use std::cout<<"Test"; or std::cin >> test;
FusedQyou
FusedQyou•2w ago
Interesting. There's no bugs in C# with this though
77_105_114_111
77_105_114_111OP•2w ago
very good
FusedQyou
FusedQyou•2w ago
Maybe because they named it cout which could be unspecific? Isn't std a class type in C++ though? Like here, we have Console You should stick those before a method, though. It's required anyway unless you put using static System.Console; at the top of the file
77_105_114_111
77_105_114_111OP•2w ago
yes it has objects like cout for output, cin for input, cerr for errors & clog for logs I guess I'm starting like C# more than C++
FusedQyou
FusedQyou•2w ago
I can't comment on C++ compared to C# but I know it's not going to introduce memory leaks or vulnerabilities as quickly 😄
77_105_114_111
77_105_114_111OP•2w ago
nice
Anton
Anton•7d ago
That's because std pulls in a crap ton of symbols. And because variable names cause conflicts with type names. In C#, you can name a property the same as another class, it will work without an issue And in C# everything is in classes, there are no free functions C++ has namespaces

Did you find this page helpful?