C# cannot explicity convert type

tmajor99
tmajor99 used Ask the Experts™
on
I have two list arrays and want to filter the results from one Array to another but I get a syntax error "cannot explicity convert type '...filtervaluesofattribure' to 'Systems.Collections.Generic.List...' .  How do I do this?  Is it possible to just filter the results back to the same LIST Array?

GetAllConvertedValue = FilteredProducts.Where(i => i.value1 == li.Text).FirstOrDefault();

List<FilteredValuesOfAttribure> GetAllConvertedValue = new List<FilteredValuesOfAttribure>();
List<FilteredValuesOfAttribure> FilteredValueOfProduct = new List<FilteredValuesOfAttribure>();
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Architect, Technical Expert
Commented:
Hi,
In you example, after
GetAllConvertedValue = FilteredProducts.Where(i => i.value1 == li.Text).FirstOrDefault();

Open in new window

, GetAllConvertedValue  is not a list but null or an instance of element of type of FilteredProducts elements.
change this to :
GetAllConvertedValue = FilteredProducts.Where(i => i.value1 == li.Text).ToList()

Open in new window

to have a list as result (none or several elements)

thus, what to you mean exactly by "Ifilter the results from one Array to another" ?
Commented:
Is it possible to just filter the results back to the same LIST Array?
Yes it is possible, however, you lose all of the contents of the master (or original) list.  Consider the following -
using System;
using System.Collections.Generic;
using System.Linq;

namespace EE_Q28690720
{
	class Program
	{
		static List<Person> people = new List<Person>() 
		{ 
			new Person() { ID = 1, Name = "Jim", Gender = Gender.Male }, 
			new Person() { ID = 2, Name = "Julie", Gender = Gender.Female }, 
			new Person() { ID = 3, Name = "Peter", Gender = Gender.Male }, 
			new Person() { ID = 4, Name = "Patricia", Gender = Gender.Female }, 
			new Person() { ID = 5, Name = "Vance", Gender = Gender.Male }, 
			new Person() { ID = 6, Name = "Vanessa", Gender = Gender.Female } 
		}; 

		static void Main(string[] args)
		{
			Console.WriteLine("Full list");
			foreach (var person in people)
				Console.WriteLine("{0} [{1}] is a {2}", person.Name, person.ID, person.Gender);

			people = (from person in people where person.Gender.Equals(Gender.Female) select person).ToList();

			Console.WriteLine();
			Console.WriteLine("Now filtered");
			foreach (var person in people)
				Console.WriteLine("{0} [{1}] is a {2}", person.Name, person.ID, person.Gender);

			Console.ReadLine();
		}
	}

	class Person
	{
		public int ID { get; set; }
		public string Name { get; set; }
		public Gender Gender { get; set; }
	}

	enum Gender : int
	{
		None = 0,
		Male = 1,
		Female = 2,
		Unknown = 3,
		Undeclared = 4
	}
}

Open in new window

Which produces the following output -Capture.JPG
-saige-

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial