Solved

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

Posted on 2006-06-13
5
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 86

Expert Comment

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

    public class person
    {
        ...
0
 
LVL 86

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

707 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