开发者

Is possible with LINQ to extract from an array of objects the value of one property and create a new array?

I'm pretty new to LINQ and开发者_开发百科 I wonder if it's possible to do the following thins:

I have an array of objects with several properties. I want to create a new array with the values of one of those properties, so if I have this class:

public class TestClass
{
    public string A {get;set;}
    public string B {get;set;}
    public string C {get;set;}
}

this is what I want to do:

public class ToDo
{
    private TestClass[] _array;

    private string[] _cProperties;

    _cProperties = queryToExtractTheValuesOfCfromTheArray_array;
}

Thanks in advance!


sure:

string[] _cProperties = _array.Select(x => x.C).ToArray();


_cProperties = _array.Select(t => t.C); //.ToArray()?
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜