Click here to Skip to main content
15,893,508 members
Home / Discussions / C#
   

C#

 
GeneralRe: How do I add 3 objects to array in C# Pin
Aindriu Mac Giolla Eoin19-Apr-15 9:32
Aindriu Mac Giolla Eoin19-Apr-15 9:32 
QuestionGoogle Spreadsheets API - Getting Data into dataGridView? Pin
Linus Agren19-Apr-15 6:00
Linus Agren19-Apr-15 6:00 
AnswerRe: Google Spreadsheets API - Getting Data into dataGridView? Pin
Linus Agren20-Apr-15 18:04
Linus Agren20-Apr-15 18:04 
QuestionCatch Win+Left (Aero-Snap)? Pin
SledgeHammer0118-Apr-15 16:01
SledgeHammer0118-Apr-15 16:01 
AnswerRe: Catch Win+Left (Aero-Snap)? Pin
Dave Kreskowiak18-Apr-15 18:47
mveDave Kreskowiak18-Apr-15 18:47 
GeneralRe: Catch Win+Left (Aero-Snap)? Pin
SledgeHammer0118-Apr-15 20:19
SledgeHammer0118-Apr-15 20:19 
SuggestionRe: Catch Win+Left (Aero-Snap)? Pin
Richard Deeming20-Apr-15 2:34
mveRichard Deeming20-Apr-15 2:34 
QuestionHow do I add an object to a list within a class? Pin
Doncal18-Apr-15 9:43
Doncal18-Apr-15 9:43 
Hi Guys,

How do I go about adding objects to a list in a class?

I have a some Property classes, that Id like to add to a list contained in another class.

C#
public class Property
{
  public string property { get; set; }
  public string value { get; set; }

  public Property() { }

  public Property(string prop, string val)
  {
    property = property;
    value = value;
  }
}

public class clsContacts
{
  public List<Property> properties { get; set; }
}


When I try something like the code below, it compiles fine, but when I run it, I get the following error:
"object reference not set to an instance of an object."

C#
Property p = new Property();
p.property = "email";
p.value = "xxxxxxxxxxx@Acme1.net";

clsContacts lstContacts = new clsContacts();

lstContacts.properties.Add(p);


Any suggestions as to what I should be doing?

Thanks

modified 18-Apr-15 16:29pm.

AnswerRe: How do I add an object to a list within a class? Pin
Pete O'Hanlon18-Apr-15 10:06
mvePete O'Hanlon18-Apr-15 10:06 
AnswerRe: How do I add an object to a list within a class? Pin
Sascha Lefèvre18-Apr-15 10:09
professionalSascha Lefèvre18-Apr-15 10:09 
AnswerRe: How do I add an object to a list within a class? Pin
Doncal18-Apr-15 10:24
Doncal18-Apr-15 10:24 
GeneralRe: How do I add an object to a list within a class? Pin
Sascha Lefèvre18-Apr-15 10:27
professionalSascha Lefèvre18-Apr-15 10:27 
GeneralRe: How do I add an object to a list within a class? Pin
BillWoodruff18-Apr-15 17:28
professionalBillWoodruff18-Apr-15 17:28 
GeneralRe: How do I add an object to a list within a class? Pin
Sascha Lefèvre19-Apr-15 0:44
professionalSascha Lefèvre19-Apr-15 0:44 
QuestionWindows remote desktop but all in HTML Pin
Dr Gadgit18-Apr-15 6:23
Dr Gadgit18-Apr-15 6:23 
QuestionCreate Chart in Excel with C# Pin
Member 836750218-Apr-15 2:17
Member 836750218-Apr-15 2:17 
AnswerRe: Create Chart in Excel with C# Pin
Brisingr Aerowing18-Apr-15 12:24
professionalBrisingr Aerowing18-Apr-15 12:24 
Questionfloat to and from frequency Pin
DaveyM6917-Apr-15 10:06
professionalDaveyM6917-Apr-15 10:06 
AnswerRe: float to and from frequency Pin
Sascha Lefèvre17-Apr-15 11:02
professionalSascha Lefèvre17-Apr-15 11:02 
GeneralRe: float to and from frequency Pin
DaveyM6917-Apr-15 13:16
professionalDaveyM6917-Apr-15 13:16 
GeneralRe: float to and from frequency Pin
Sascha Lefèvre17-Apr-15 13:48
professionalSascha Lefèvre17-Apr-15 13:48 
GeneralRe: float to and from frequency Pin
DaveyM6917-Apr-15 14:15
professionalDaveyM6917-Apr-15 14:15 
GeneralRe: float to and from frequency Pin
Sascha Lefèvre17-Apr-15 14:29
professionalSascha Lefèvre17-Apr-15 14:29 
GeneralRe: float to and from frequency Pin
DaveyM6918-Apr-15 0:01
professionalDaveyM6918-Apr-15 0:01 
GeneralRe: float to and from frequency Pin
Sascha Lefèvre18-Apr-15 3:53
professionalSascha Lefèvre18-Apr-15 3:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.