Solved

pass a class from a form to another form in visual studio 2005

Posted on 2006-06-13
5
202 Views
Last Modified: 2010-04-16
I have a class person

class person
    {
        public person()
        {
           
        }
        protected string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
In main form :
        private person NewPerson = new person();        
        private void button1_Click(object sender, EventArgs e)
        {
            Form2 frm = new Form2();
            frm.ShowDialog();
            NewPerson = frm.GetInfo();
        }
In form2 :
        person personal = new person();
        public person GetInfo()                     // ERROR HERE ????
        {
            return personal;
        }      
        private void Form2_Load(object sender, EventArgs e)
        {
            personal.Name = "Test Only";
        }
Error      1      Inconsistent accessibility: return type 'Project.person' is less accessible than method 'Project.Form2.GetInfo()'      
Note : everything working well in Visual studio 2003.
Pls help me !
0
Comment
Question by:knowlegde
  • 2
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 100 total points
ID: 16896014
Hi, I think its because C#'s default access modifier is "private" and  you havn't specified one for the person class... change the declaration of the person class to "public":

public class person
    {
        public person()
        {
           
        }
        protected string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
...
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 16896030
Make sure your class person() has been declared as public...

    public class person
    {
        ...
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 16896035
I shoulda refreshed eh?...  =)
0
 
LVL 18

Expert Comment

by:Ravi Singh
ID: 16896049
no worries :)
0
 

Author Comment

by:knowlegde
ID: 16899049
It's realy a silly mistake.Thank all. :)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question