c# - Can not reference a type through an expression why? -


I'm trying to create 2 forms.

In Form 1, I want to save all new contacts, so I can display them later, and I am adding Form 2 to open another button where I want to make a contact and form 1 After closing the window to save the contact in the list created in I'm getting the error:

  on any expression  

on f2.Contacts = this.contacts Can not reference and I do not know why.

Form 1:

 Using the  system; Using System.Collections.Generic; Using System.ComponentModel; Using System.Data; Using System.Drawing; Using System.Linq; Using System.Text; System usage threading. Task; Using System.Windows.Forms; Name Location WindowsFormsApplication1 {Public Partial Class} Form 1: Form {Public Contact Contact = New Contact (); Public Form 1 () {Initialization (); } Public category contacts {Private list & lt; Contacts & gt; People = new list & lt; Contacts & gt; (); Public listing & lt; Contacts & gt; People come back {people; }}} Private Zero Button 1_Click (Object Sender, EventEurge E) {Form 2 F2 = New Form 2 (); F2. Contacts = this.contacts; F2.Show (); }}}  

Form 2:

  using the system; Using System.Collections.Generic; Using System.ComponentModel; Using System.Data; Using System.Drawing; Using System.Linq; Using System.Text; System usage threading. Task; Using System.Windows.Forms; Namespace WindowsFormsApplication1 {Public Partial Category Form 2: Form {Public Category Contact {Private List & lt; Person & gt; Person = new list & lt; Person & gt; (); Public listing & lt; Person & gt; {Come back to the people }}} Public Contact Contact {get; Set; } Public Form 2 () {Initialization (); } Private Zero Button 1_Click (Object Sender, EventArgs e) {Person P = New Person (); P.Name = textbox1.Text; P.LastName = textBox2.Text; P. Phone number = text box 3 Text; P.eMail = textBox4.Text; This.contacts.Persons.Add (P); } Public class person {public string name {get; Set; } Public String LastName {get; Set; } Receive the public string phone number { Set; } Public string e-mail {get; Set; }}}}}  

You (mistakenly) nested mentioning contacts Are class

  you use F2. Contacts = this.contacts;  

Look at class Form2.Contacts .

But you Form2.contacts properties :

  f2.contacts = this.contacts;  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -