locked
Linq error

    Question

  • I have a code from Windows Phone C# and I am trying to use in Windows 8 apps

    I am using System.Linq and all Linq terms show error:

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

     int[] val = rev.Select(c => int.Parse(c.ToString())).ToArray();

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

    for (int i = 0; i < val.Length; i++)
    {
        aux[i] = (val[i] * m[i]).ToString();
        sum += aux[i].Sum(c => c - '0');
    }


    GHELFER


    What is wrong?
    • Edited by helferg01 Sunday, May 18, 2014 10:14 PM missing question
    Sunday, May 18, 2014 10:12 PM

Answers

  • The answer:

    Windows 8 Store Apps target WinRT (Windows Runtime).

    For that reason, because WinRT can be targeted using C# and there're a lot of classes from .NET Framework having a match in WinRT, most of available code base not using very specific libraries may work also on Windows 8 Store Apps.



    GHELFER




    Monday, May 19, 2014 1:49 PM

All replies

  • Hi helferg01,

    Your first code works find on my side, I assume your string list contains correct items which can be converted to an int type.

                string[] rev = new string[] { "123", "123", "12312" };
                int[] val = rev.Select(c => int.Parse(c.ToString())).ToArray();

    I got no error message while executing the code. The namespace is "using System.Linq" as you mentioned. Or can you provide me more information for instance what's the difference between your code and mine, also you could share a simple demo with us for a better analysis.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, May 19, 2014 2:14 AM
    Moderator
  • my references...

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using Windows.ApplicationModel.DataTransfer;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.System;
    using Windows.UI.ApplicationSettings;
    using Windows.UI.Popups;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Controls.Primitives;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Input;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Navigation;
    seems like not loaded...


    GHELFER


    • Edited by helferg01 Monday, May 19, 2014 3:06 AM LINQ not loaded?
    Monday, May 19, 2014 2:44 AM
  • Hi helferg01,

    Your reference works fine on my side.

    Linq not loaded? Let's say if you create a blank app and could you use the linq inside? Or still not possible?

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, May 19, 2014 6:34 AM
    Moderator
  • Perhaps check if they are path of the references are correct.
    Monday, May 19, 2014 6:46 AM
  • I did that soon as the problem comes, and not worked also. I though was a VS2012 then I created an other app in forms and all were doing well.

    I created too a library with this linq methods  and during the reference show an error: The project targets '.NETCore' while the file reference targets '.NETFramework'. This is not a supported scenario.

    PortableLibrary same error above appear.

    I see that LINQ is working for List not for string (?).


    GHELFER



    • Edited by helferg01 Monday, May 19, 2014 1:24 PM
    Monday, May 19, 2014 12:18 PM
  • The answer:

    Windows 8 Store Apps target WinRT (Windows Runtime).

    For that reason, because WinRT can be targeted using C# and there're a lot of classes from .NET Framework having a match in WinRT, most of available code base not using very specific libraries may work also on Windows 8 Store Apps.



    GHELFER




    Monday, May 19, 2014 1:49 PM