How to use Contains in Collection of Objects for a property field code example

Example 1: check property type of collection c#

var obj = new PropClassDemo();
foreach (PropertyInfo prop in obj.GetType().GetProperties())
{
	if(prop.PropertyType != typeof(string) && typeof(IEnumerable).IsAssignableFrom(prop.PropertyType))
	{
		Console.Writeline("This prop's type is Ienumerable");
	}
}

//Note: string is an ienumerable too

Example 2: find the property is matching

let wantedProperty = (arrayOfObjects.find(obj => obj.id === wantedObject.id) || {}).title || 'None Found';

Tags:

Misc Example