Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

c# StringExtension with Method Space

I try to create a string extension with the method Space(int) in it. If I have an instance of a string, then its no problem. But without I have no Idea.

The call should be: string.Space(2) or String.Space(2)

Not "".Space(2)!!!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In this example, the method should return 2 space characters (" ").

Anybody to help?

>Solution :

An extension method is supposed to act on an object instance, that’s how and why it has the syntax it got.

But in your case, your method does not act on a string instance, so what’s the point of trying to define it as a string extension method? Just keep it an old boring static method. There’s nothing wrong with ye’ole static methods…

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading