Libraries of functions
-
Hi All, This might stem back to 'C' days and I probably ought to change my 'mindset' and other such phrases but old habits die hard. Call me Cliché Man... When I write an applicaton, I tend to have a source file or two put aside to put all 'those little useful functions' in. You know, generic things like formatting a postal code, validating things etc. that don't fit in with a specific class anywhere. Well, using C#, I've implementing this as follows: In library.cs:
namespace mylib { public class rog { static public int DoSomething(int arg) { return arg+1; } } }
To call this function, I'm putting this in app1.cs:using mylib; ... b = rog.DoSomething(3);
This seems like using a class where there is really no need. I'd like to just call 'DoSomething(3)' without the 'rog.' part. I'm new to C# so be gentle, I'm old to C and C++ so feel free to be harsh. Am I being stupid? Thanks for any confirmation or denial... Rog -
Hi All, This might stem back to 'C' days and I probably ought to change my 'mindset' and other such phrases but old habits die hard. Call me Cliché Man... When I write an applicaton, I tend to have a source file or two put aside to put all 'those little useful functions' in. You know, generic things like formatting a postal code, validating things etc. that don't fit in with a specific class anywhere. Well, using C#, I've implementing this as follows: In library.cs:
namespace mylib { public class rog { static public int DoSomething(int arg) { return arg+1; } } }
To call this function, I'm putting this in app1.cs:using mylib; ... b = rog.DoSomething(3);
This seems like using a class where there is really no need. I'd like to just call 'DoSomething(3)' without the 'rog.' part. I'm new to C# so be gentle, I'm old to C and C++ so feel free to be harsh. Am I being stupid? Thanks for any confirmation or denial... Rog -
Hi All, This might stem back to 'C' days and I probably ought to change my 'mindset' and other such phrases but old habits die hard. Call me Cliché Man... When I write an applicaton, I tend to have a source file or two put aside to put all 'those little useful functions' in. You know, generic things like formatting a postal code, validating things etc. that don't fit in with a specific class anywhere. Well, using C#, I've implementing this as follows: In library.cs:
namespace mylib { public class rog { static public int DoSomething(int arg) { return arg+1; } } }
To call this function, I'm putting this in app1.cs:using mylib; ... b = rog.DoSomething(3);
This seems like using a class where there is really no need. I'd like to just call 'DoSomething(3)' without the 'rog.' part. I'm new to C# so be gentle, I'm old to C and C++ so feel free to be harsh. Am I being stupid? Thanks for any confirmation or denial... RogYou can't do that in C# In latest java (1.5) you can do static import and in C# 2.0 you can have static class that will force you to have only static members and can't instentiate that class. One possible (but not recommended) solution would be to have class rog { ... static methods here... } class myclass : rog { ... now you can call methods of rog without rog. }
-
You can't do that in C# In latest java (1.5) you can do static import and in C# 2.0 you can have static class that will force you to have only static members and can't instentiate that class. One possible (but not recommended) solution would be to have class rog { ... static methods here... } class myclass : rog { ... now you can call methods of rog without rog. }
That's sort of what I'm after - I didn't think of deriving my class from the library - seems a roundabout way of resolving the function names though. What I'm after really is a way of defining functions in the same way as you would, for example, the 'sin()' function as I'd much rather use: result = sin(pi*4); then result = rog.sin(pi*4); The library doesn't have any actual data (or if it is, it'll be static) and I don't intend to instantiate an instance of it. I still have this nagging feeling that I just haven't 'got the hang' of C# yet...! Rog