469,343 Members | 5,380 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

what is a helper class?

I have heard about helper classes, but can somebody please explain to me
what they are and what they are used?

*** Sent via Developersdex http://www.developersdex.com ***
Aug 21 '07 #1
6 46427
Mike P <mi*******@gmail.comwrote:
I have heard about helper classes, but can somebody please explain to me
what they are and what they are used?
They're usually classes just with static methods acting on another
class. Something like:

public static class StringHelper
{
public static string Reverse(string input)
{
(Code goes here)
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 21 '07 #2
"Helper class" is just a term to refer to a class that provides methods that
"help" do something. A well - know example is the Data Access Application
Blocks v2 "SqlHelper" class, which helps perform common data access functions.

-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Mike P" wrote:
I have heard about helper classes, but can somebody please explain to me
what they are and what they are used?

*** Sent via Developersdex http://www.developersdex.com ***
Aug 21 '07 #3
Another example is : HttpUtility class.
--
Sincerely
Yaron Karni
http://dotnetbible.blogspot.com/
"Mike P" wrote:
I have heard about helper classes, but can somebody please explain to me
what they are and what they are used?

*** Sent via Developersdex http://www.developersdex.com ***
Aug 21 '07 #4
Jon,

What would be the reason for creating a class just with static methods
acting on another class?
Thanks,

Mike
*** Sent via Developersdex http://www.developersdex.com ***
Aug 21 '07 #5
Mike P <mi*******@gmail.comwrote:
What would be the reason for creating a class just with static methods
acting on another class?
It collects them together. Often you can't add methods to a class
itself, because you don't have the code - I can't add the Reverse
method to string, for example.

If you're going to frequently do the same things with an instance of a
class, it's worth putting that somewhere rather than repeating the
code.

Another example is in my miscellaneous utility library
(http://pobox.com/~skeet/csharp/miscutil) - I've got a helper class for
working with streams. It has a set of methods to copy the contents of
one stream to another, and another set to read the complete contents of
a stream as a byte array.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 21 '07 #6
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
Mike P <mi*******@gmail.comwrote:
>What would be the reason for creating a class just with static methods
acting on another class?

It collects them together. Often you can't add methods to a class
itself, because you don't have the code - I can't add the Reverse
method to string, for example.
You can with C# V3.0 by adding "this" to the methods argument, ie:

public static class StringHelper
{
public static string Reverse(this string input)
{
(Code goes here)
}
}

....

using StringHelper;

string myString;
....

string reveresedString = myString.Reversed();
Aug 21 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Mario S. | last post: by
1 post views Thread by amber | last post: by
6 posts views Thread by Alex Hunsley | last post: by
3 posts views Thread by oaklander | last post: by
3 posts views Thread by Hongyu | last post: by
13 posts views Thread by Hussein B | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.