c# - Comparing objects from two instances of a Class and storing result in List<class> -


i pretty asked question yesterday, i'm going reform new question , more specific.

here question asked yesterday.

i have list of class type (ex. eshclass)

list<eshclass> eshlist; 

and eshclass composed of elements like:

public class eshclass{   public string policynumber;   public string policymod;   public string multipolicy;   public string hasswimmingpool; }; 

so eshlist has policies(eshclass) , there values equal:

eshlist[0].policynumber= "7"; eshlist[0].policymod= "00"; eshlist[0].multipolicy= "yes"; eshlist[0].hasswimmingpool= "no";  eshlist[1].policynumber= "7"; eshlist[1].policymod= "00"; eshlist[1].multipolicy= "no"; eshlist[0].hasswimmingpool= "yes"; 

so have 2 instances of eshclass data has been set , being stored in eshlist.

the next part other post got warry. want compare objects like:

eshlist[0].policynumber == eshlist[1].policynumber //i know isn't correct code                                                     //just show how compare.  eshlist[0].hasswimmingpool == eshlist[1].hasswimmingpool 

and if 2 objects i'm comparing different want keep them in list print them on webpage made mvc 4 , page listview.

my post yesterday asking more doing in efficient way...today got thinking , idk if i'll able away doing each element... right i'm doing it:

public list<eshlist> compare(list<eshclass> pollist)         {             var l = pollist;             if (l[0].policynumber.equals(l[1].policynumber))                 l[0].policynumber = l[1].policynumber = null;             if (l[0].hasswimmingpool.equals(l[1].hasswimmingpool))                 l[0].hasswimmingpool = l[1].hasswimmingpool= null;     } 

so equal elements nulled out , different elements returned in list. i'm calling compare method:

index.cshtml:

{  ...  return view((esh.compare(eshlist)).defaultifempty()); } 

so after showing more detailed explanation think there's way away long series of ifs or better way i'm trying today yet keep result in list can print on screen? said in other post i'm newer c# , new web programming. if have helpful answers or articles reference, please let me know! thank you!

edit: show using example screen show

policy1

policymod yes hasswimmingpool no

policy2

policymod no hasswimmingpool yes

the best way make eshclass know how compare equality.

see this link in-depth example, or this question more minimal set.

basically, give code enough information able evaluate eshlist[0] == eshlist[1] directly.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -