learning c# on my own , in a new project i have started working on,
one of the methods, accepts a List<string> type data, passed in as a parameter
. i would like to know , now …that the need is for two of those lists, two types of data, or two groups,
and just for this example , say i have a pros and cons, or.. girls and boys,
these are actually 2 separated lists of elements or objects, i need to pass in, as a parameter
, and i want it to be passed as-one data-Type, and then, inside the method i will take care of separation of data lists , so.. instead of a couple of List objects i, thought(for a second there , that a Dictionary will be suitable…)
though i will only have one element (one item… each is a List) ,in this data type that i need to pass
what can i do to get this result ?
i will try to illustrate it :
List<string> classGirls = new List<string>();
List<string> classBoys = new List<string>();
for eace item in source… load both from the source
done List girls + List Boys are populated how would you pass them as one as a Dictionary Could though knowing you will only have One Girls And One Boys ListObjects ?
public bool foundAMatch( string Lookup, List<string> G , List<string> B){
{
var firstGirl = G.ElementAt(0);
var firstBoy = B.ElementAt(0);
return firstGirl == Lookup && firstBoy !=Lookup ;
}
instead i need it to be something Like
public bool foundAmatch(string Lookup, someDataType.... Kids)
{
var firstGirl = kids-girls <-- first entity in kids;
var firstBoy = kids-boys <-- first entity in Kids;
return firstGirl == Lookup && firstBoy !=Lookup ;
}
few things in mind …as to properties of data , it should have good performance… naturally desired, though most importantly, it should be appropriate /easy to arrange and suitable for iterations using loops for sorting and as subject to all kind of statistic operations .
- question is,
how will you implement the logic , is it an existing data Type… that i am thinking of ?
if it’s not, what approach will you implement in this scenario choosing / crafting a data Type ?
You can solve this easily by using inheritance:
edit:
I quite like extension methods, so I’d write the method like this:
which you can then use like:
edit2:
It’s probably even better to just have gender as a property of the
Personclass:and change the method to: