I pretty much asked this question yesterday, but i'm going to reform it as a new question and be more specific.
Here is the question I asked yesterday.
I have a list of a class type (ex. ESHClass)
List<ESHClass> eshlist;
And ESHClass is composed of elements like:
public class ESHClass{
public string PolicyNumber;
public string PolicyMod;
public string MultiPolicy;
public string HasSwimmingPool;
};
So say eshlist has to policies(ESHClass) and 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 I have two instances of my ESHClass that the data has been set and they are being stored in eshlist
.
The next part is where my other post got warry. I want to compare the objects like:
eshlist[0].PolicyNumber == eshlist[1].PolicyNumber //I know this isn't correct code its
//just to show how I would compare.
eshlist[0].HasSwimmingPool == eshlist[1].HasSwimmingPool
and then if the two objects i'm comparing are different I want to keep them in a list to print them on my webpage which I made with MVC 4 and the page is a ListView.
My post from yesterday was asking more about doing this in the most efficient way...today I got to thinking about it and idk if i'll really be able to get away from doing it for each element... right now this is now 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 all the equal elements are nulled out and only the different elements are returned in the list. This is where i'm calling the Compare method:
Index.cshtml:
{
...
return View((esh.Compare(eshList)).DefaultIfEmpty());
}
So now after showing a more detailed explanation do you think there's a way to get away from a long series of ifs or just a better way to do what i'm trying today yet keep the result in a list I can print on the screen? As I said in my other post i'm newer to C# and completely new to web programming. If you have any helpful answers or articles I could reference, please let me know! Thank you!
EDIT: Just to show using my example what my screen will show
Policy1
PolicyMod Yes HasSwimmingPool No
Policy2
PolicyMod No HasSwimmingPool Yes