• C# - Namepaces, functions...
    5 replies, posted
So, I just started C#, making simple console apps. I was wondering if it would be possible and practical, useful, to make all my functions in a independant .cs file with a namespace. Would I be able to call these functions by doing Namespace.Function ?
You can put them in a class, then put the class in a namespace. To call it you would do Namespace.Class.Function The functions would have to be static
If it's in the same namespace then you can just do Class.Function() I'm hoping you're not just using a bunch of static functions like it was a procedural language.
It sounds to me like you want to program procedurally in C#, that is not a very good idea. I personally like to put classes in separate files but that is just because in java each public class has to be in its own file and I carried the habit over(this may also be true in c# as well). Usually classes do pretty different things so it is logical to separate them, there are cases where there is not need to separate classes in different files(event listeners in java). Try not to have different classes for each method, think of a class like a definition of a type of thing that has atributes(variables) and actions(methods). I realize that it can be hard to really think like this for short console apps but for larger apps it is worth it. And on a nitpicking note, in Object Oriented programming functions are called methods, in fact I think procedural languages tend to call them procedurs while functional languages(such as F#) call them functions.
[QUOTE=Ortzinator;22418654] I'm hoping you're not just using a bunch of static functions like it was a procedural language.[/QUOTE] For now, it's not a bunch, but that is what I was planning to do :D I'll remember it. And thanks everyone.
In languages like Pascal, Ada and Visual Basic, a function is something that returns a value but a Procedure or a Subroutine is something which does not return a value - although you can still pass the memory address of something to a subroutine and have its value set by that subroutine.
Sorry, you need to Log In to post a reply to this thread.