Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9213023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:39:16+00:00 2026-06-18T01:39:16+00:00

In .NET for Windows Store Apps –it seems– you cannot use strings as Enumerables

  • 0

In .NET for Windows Store Apps –it seems– you cannot use strings as Enumerables anymore. The following code works for desktop applications, but not for apps:

public static bool SolelyConsistsOfLetters(string s)
{
    return s.All(c => char.IsLetter(c));
}

The error is

‘string’ does not contain a definition for ‘All’ and no extension method ‘All’ accepting a first argument of type ‘string’ could be found (are you missing a using directive or an assembly reference?)

But I’m not missing an assembly reference or using System.Linq;. The following code does work:

public static IEnumerable<char> StringAsEnumerable(string s)
{
    foreach (char c in s)
    {
        yield return c;
    }
}

public static bool SolelyConsistsOfLetters(string s)
{
    return StringAsEnumerable(s).All(c => char.IsLetter(c));
}

The problem is, s as IEnumerable<char> does not work (error: “Cannot convert type ‘string’ to ‘System.Collections.Generic.IEnumerable’ (..)”) and s.GetEnumerator() is not available.

My questions:

  1. Is there really no elegant way to use strings as Enumerables (without a helper method as above)? I feel like I must be missing something totally obvious.
  2. Since the string does not behave like an Enumerable, why/how does foreach work here?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:39:17+00:00Added an answer on June 18, 2026 at 1:39 am

    The String.IEnumerable<Char>.GetEnumerator method is not supported in .NET for Windows Store applications, however, the non generic String.IEnumerable.GetEnumerator is supported so that’s why the foreach approach works.

    Based on that I believe it should also be possible to do:

    s.Cast<char>().All(c => char.IsLetter(c))
    

    UPDATE (regarding Jani comment)
    The foreach is already performing the cast by defining the each variable as char. The nongeneric IEnumerable version returns object and at compile time every cast from object to any other type is acceptable so that’s why it works.

    The following code will also compile fine but will fail at runtime:

    var valid = new object[] {'1', '2', '3'};
    
    foreach (char c in valid)
        Console.WriteLine(c);
    
    var invalid = new object[] { 1, 2, 3 };
    
    foreach (char c in invalid)
        Console.WriteLine(c); // Fails at runtime; InvalidCastException
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got the following code running in a Windows Store application that is supposed
I'm writing a pluralization framework using .NET for Windows Store apps. For a custom
I have a Portable Class Library that targets .NET for Windows Store apps and
I use stock JSON serialiser in .NET 4.5 windows store app - System.Runtime.Serialization.Json.DataContractJsonSerializer I
Thread.Sleep doesn't seem to be supported in .NET for Windows Store apps. For example,
CultureInfo.GetCultures does not exist in the .NET API for Windows Store apps. How could
In the .NET API for Windows Store Apps the Path class does not have
In a .Net 3.5 (Windows) service, I would like to store a small collection
I have a Windows.Forms based .NET desktop application that stores privileged information in a
I have a VB.NET Windows Service that I wrote and it works fine. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.