generic collection differencing

  • Thread starter Thread starter rodchar
  • Start date Start date
R

rodchar

hey all,

is there by any chance a way to compare 2 generic collections and if one is
different to merge changes to original?

also, is there a way to copy a singe field from one generic collection to
another?

thanks,
rodchar
 
hey all,

is there by any chance a way to compare 2 generic collections and if one
is
different to merge changes to original?

Yes, depending on your definition of "merge". See Enumerable.Union()
method for example.
also, is there a way to copy a singe field from one generic collection to
another?

IMHO, that makes no sense. A collection doesn't have "a single field".

Pete
 
rodchar said:
hey all,

is there by any chance a way to compare 2 generic collections and if one is
different to merge changes to original?

also, is there a way to copy a singe field from one generic collection to
another?

thanks,
rodchar


The following code copies the Name field of a collection of Dummy
objects to another collection. Is that what you mean?

public class Dummy
{
public string Name { get; set; }
public string Phone { get; set; }
}

class Program
{
static void Main(string[] args)
{
List<Dummy> Dummies = new List<Dummy>()
{
new Dummy(){Name="Alphonse Tomato", Phone="123-456-7890"},
new Dummy() {Name="Bella Babzug", Phone = "444-444-4444"}
};

List<string> names = (from d in Dummies
select d.Name).ToList<string>();

foreach (string n in names)
Console.WriteLine(n);

Console.ReadKey();
}
}
 
thanks all for the help,
rod.

Family Tree Mike said:
rodchar said:
hey all,

is there by any chance a way to compare 2 generic collections and if one is
different to merge changes to original?

also, is there a way to copy a singe field from one generic collection to
another?

thanks,
rodchar


The following code copies the Name field of a collection of Dummy
objects to another collection. Is that what you mean?

public class Dummy
{
public string Name { get; set; }
public string Phone { get; set; }
}

class Program
{
static void Main(string[] args)
{
List<Dummy> Dummies = new List<Dummy>()
{
new Dummy(){Name="Alphonse Tomato", Phone="123-456-7890"},
new Dummy() {Name="Bella Babzug", Phone = "444-444-4444"}
};

List<string> names = (from d in Dummies
select d.Name).ToList<string>();

foreach (string n in names)
Console.WriteLine(n);

Console.ReadKey();
}
}
 
Back
Top