Avatar of CipherIS
CipherIS
Flag for United States of America

asked on 

C# Linq Select From List

Below is some sample code.  I am trying to figure out how to use LINQ and select data from a List<> and return it to an object.  Code I am trying to resolve is located below the ?????.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test
{
    public class Product
    {
        public class ProductData
        {
            public string PropertyName { get; set; }
            public string Description { get; set; }
            public string Value01 { get; set; }
            public string Value02 { get; set; }
            public string Value03 { get; set; }
        }

        public class ProductRepo
        {
            public string PropertyName { get; set; }
            public string Description { get; set; }
        }

        List<ProductData> _productData = new List<ProductData>();

        public Product(List<ProductData> productData)
        {
            _productData = productData;

            //???????

            //var result = from x in _productData
            //             select new List<ProductRepo>()
            //             {
            //                 x.PropertyName,
            //                 x.Description
            //             };

            List<ProductRepo> productRepo = (from x in _productData
                                             select new List<ProductRepo>()
                                             {
                                                PropertyName = x.PropertyName,
                                                x.Description
                                             });
        }
    }
}

Open in new window

C#LINQ Query

Avatar of undefined
Last Comment
CipherIS

8/22/2022 - Mon