Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9016871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:07:12+00:00 2026-06-16T04:07:12+00:00

learning c# on my own , in a new project i have started working

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:07:13+00:00Added an answer on June 16, 2026 at 4:07 am

    You can solve this easily by using inheritance:

    public abstract class Person
    {
        public string Name { get; private set; }  // The setter is private because we only have to set this name when we create an instance
    
        protected Person(string name)
        {
            Name = name;
        }
    }
    
    public class Male : Person
    {
        public Male(string name) : base(name)  // This constructor calls the constructor of the class it inherits and passes on the same argument
    }
    
    public class Female : Person
    {
        public Female(string name) : base(name)
    }
    
    public bool IsMatch(string needle, IEnumerable<Person> haystack)
    {
        var firstGirl = haystack.OfType<Female>().FirstOrDefault();
        var firstBuy = haystack.OfType<Male>().FirstOrDefault();
        return firstGirl != null &&
               firstGirl.Name == needle &&
               firstBoy != null &&
               firstBoy.Name != needle;
    }
    

    edit:

    I quite like extension methods, so I’d write the method like this:

    public static class PersonExtensions
    {
        public static bool IsMatch(this IEnumerable<Person> haystack, string needle)
        {
            // same method logic in here
        }
    }
    

    which you can then use like:

    var people = new List<Person>();
    people.Add(new Male { Name = "Bob" });
    people.Add(new Female { Name = "Mary" });
    var isMatch = people.IsMatch("Jane");
    

    edit2:

    It’s probably even better to just have gender as a property of the Person class:

    public enum Sex
    {
        Male,
        Female
    }
    
    public class Person
    {
        public string Name { get; private set; }
        public Sex Gender { get; private set; }
    
        public Person(string name, Sex gender)
        {
            Name = name;
            Gender = gender;
        }
    }
    

    and change the method to:

    var firstGirl = haystack.FirstOrDefault(p => p.Gender == Gender.Female);
    var firstBoy = haystack.FirstOrDefault(p => p.Gender == Gender.Male);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to designing my own database. My project is orders/products/inventory type data,
I have been working on my own library/framework for the learning experience for a
I'm new to Lucene, i started learning the version 3 branch and there's one
I am just learning Java and have created my own Word List and Word
I am just setting up a new VPS learning to setup my own web
I'm trying to create my own template for a List class as a learning
I have started working on what I expect to become, by far, the largest
I'm about to start working on a new project at a somewhat new job,
I enjoy learning and doing things on my own, but I have run into
Doing some initial research on a new project and one of my requirements is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.