1

I'm just wondering if there is in .Net framework method which returns ASCII chars sequence? Something like:

public static string ascii()
{
    return "abcdefghijklmnuopqrstuvwxyz";
}
2
  • You can return a byte array using Ascii encoding and every byte of the array is a char wich you can parse, manipulate, use convert.tochar(value) to get the char, etc. Commented Nov 9, 2012 at 7:52
  • demas - nothing to do with your question but have you looked at iron python on .Net? Commented Nov 9, 2012 at 8:01

2 Answers 2

2

In fact String already implements IEnumerable<Char>, so your code is already you need. But you can make it more specific by changeing the return type:

    public IEnumerable<Char> Ascii
    {
        get
        {
            return "abcdefghiklmnopqrstuvwxyz";
        }
    }

If you really like to make it in a more LINQish way you could also write:

    public IEnumerable<Char> Ascii2
    {
        get
        {
            return Enumerable.Range((int)'a', 26).Select(i => (char)i);
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

1

Uhm, you wrote it there. And no, there is nothing in the framework to do so. Why would there be? This method isn't solving a particular problem and it's downright trivial to write yourself. Note though, that the naming convention would dictate the name Ascii :-)

4 Comments

I'm move code from python to c# and python has such function in standard library (string.ascii_lowercase).
News flash: .NET is not Python.
An even better name would be EnglishAlphabet, since there are 128 ASCII characters and this only returns 26 of them...
Indeed. It's the Latin alphabet, though ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.