Simple example on namespaces as a contianer for simple functions

Hi.

  I am new to the C# programming world but have been doing Delphi for over 6 years so I am not new to programming in general.  I am trying to get a handle on namespace and how to use them.  If I were creating an object that my application is to use, I think I could do this with the knowledge that I have already.  What I am having problems with is trying to move some of my utilies to C#.  Here is an example of what I am trying to do.

using System;

namespace MyLib
{
      namespace MyStrUtils
           {

//  think that I am suppost to have a class define here

                public char FirstCharInStr(string S);
                           {

                            }

            }

      namespace MyNumUtils
           {
//  think that I am suppost to have a class define here

                public int WhichIntIsLarger(int a; int b);
                           {

                            }

            }
}        


Now please do not get hung up that C# most likely has method for doing the things that I have shown here (**THIS IS ONLY TO SHOW A SIMPLE EXAMPLE OF WHAT IT IS THAT I AM TRYING TO DO**).  So as I mention in the example, I think that I am suppost to create a class and if this is true what would be a valid class name here.

 Finally question is how would I use it in a project ie:

using MyLib.MyNumUtils;


///  code
int c = (WhichIntIsLarger(10, 14));

Hope this make sense.  Thank you for your help with this.

James
thumper631Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ryerrasCommented:
Just the way you showed, by the way, we use comma to separate the arguments of a method, not semi colon. I am sure you are aware of it
0
ryerrasCommented:
By the way, if the utility is a dll, then you should add the dll to by Add Reference. Otherwise it wouldnt compile in VS.NET, if you are planning to compile in command, you should pass the referenced dll as the compile argument.
0
Razzie_Commented:
Well you cannot declare methods directly in a namespace, so you should indeed create a class. For example:

namespace MyLib
{
   namespace MyStrUtils
   {
      public class StringManipulator
      {
           public static char FirstCharInStr(string S);
           { // .... //  }
      }
   }
}

'The name 'static' means that you don't have to create an instance of StringManipulator, so you could actually use it in another project using:

Char c = MyLib.MyStrUtils.StringManipulator.FirstCharInStr("SomeString");

or if you'd use 'using MyLib.MyStrUtils;' in your code, simply:

Char c = StringManipulator.FirstCharInStr("SomeString");


HTH,

Razzie



             
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.