2 Replies - 364 Views - Last Post: 15 November 2009 - 11:49 PM Rate Topic: -----

#1 Squirrel  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 86
  • Joined: 06-February 07

Method 'Packages' in C#?

Posted 15 November 2009 - 09:37 PM

I was wondering if there is any way to define 'packages' of functions/procedures in C#, so that many classes can use them. I'm a bit used to Ada at this point, so any help with this very basic problem would be a plus. Can you just create a special kind of class for such a purpose? The plan is to do something like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyNamespaceName
{
	// FUNCTIONS/PROCEDURES GO HERE
}



Thanks for your help.

EDIT: I see how the 'static' keyword can make the functions/procedures available like a package, so defining a class is a good option. Is this the only way in C#?

This post has been edited by Squirrel: 15 November 2009 - 10:07 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Method 'Packages' in C#?

#2 knichols  Icon User is offline

  • New D.I.C Head

Reputation: 10
  • View blog
  • Posts: 21
  • Joined: 09-November 09

Re: Method 'Packages' in C#?

Posted 15 November 2009 - 10:13 PM

Creating the static class would be a good way to do it. Another thing you might want to think about is using extension methods like this.

public static class Extensions
{
	 public static string ToHexString(this UInt32 Value)
	 {
		 return Value.ToString("X8");
	 }
}




With this you can use it anywhere in your program like this.

private void button1_Click(object sender, EventArgs e)
{
	 UInt32 x = UInt32.MaxValue;
	 MessageBox.Show(x.ToHexString());
}


Was This Post Helpful? 0
  • +
  • -

#3 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Method 'Packages' in C#?

Posted 15 November 2009 - 11:49 PM

.NET contains classes like what you wish to do (System.Math is probably the most commonly used). They just have methods/constants in them that are useful for performing specific tasks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1