Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I have a class.

----------------***------------------------------

C#
public string NameEN { get; set; }
public string CandidateIDs { get; set; }

public List<CandidateInfo> CandidateList
{
    get
    {
        string[] CandidatesID = CandidateIDs.Split(',');
        List<CandidateInfo> candidateList = CandidatesID.Select(c => CandidateController.Instance[Convert.ToInt32(c.Trim())]).Where(item => item != null).ToList(); // Candidate List
        //candidateList.AddRange(NameEN);
        return candidateList.Count > 0 ? candidateList : null;
    }

}


What I have tried:

I want to add Candidate Group Name to the Candidate List.

i have tired this code
//candidateList.AddRange(NameEN);//NEW COLUMN


please help me guys


Thanks
Posted
Updated 3-Oct-16 3:49am
v4
Comments
Richard MacCutchan 3-Oct-16 4:57am    
Your question makes no sense, a List does not have columns, it just contains a group of items.
abdul subhan mohammed 3-Oct-16 5:37am    
Hi Richard,
yes, u r rit, but i have candidiateInfo, which contains candidate id, name, cell no, age...etc..

Richard MacCutchan 3-Oct-16 6:05am    
What does that mean? Please edit your question and explain (using proper words not txtspk) what your problem is. Saying that you want to add a column to a List makes no sense.
Suvendu Shekhar Giri 3-Oct-16 5:13am    
new column?
What exactly is your requirement?
abdul subhan mohammed 3-Oct-16 5:40am    
as i'm filing candidateInfo in my list, which contains, candidate id, name, cell no, age...etc.. in the same list i want to add GroupName

1 solution

So your you just need to add the missing properties to your class.

Quote:
as i'm filing candidateInfo in my list, which contains, candidate id, name, cell no, age...etc.. in the same list i want to add GroupName


Your class should look something like the follow, not sure what that code snippet you posted is from.

C#
public class CandidateInfo
{
   public int CandidateId {get;set;}
   public string Name {get;set;}
   public string CellNo {get;set;}
   public int Age {get;set;}
   //Add more properties here as you need them. Ex:
   public string GroupName {Get;set;}
}


Then you'll be able to access/assign values to any properties you add later on while using the CandidateInfo class. Ex:

C#
var candidates = new List<CandidateInfo>();
var c1 = new CandidateInfo();
c1.Name = "Matt";
c1.GroupName = "Group 1";

var c2 = new CandidateInfo();
c1.Name = "Mark"
c1.GroupName = "Group 2";

candidates.Add(c1);
candidates.Add(c2);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900