Solved

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

Posted on 2006-06-13
5
196 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
Comment Utility
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
Comment Utility
Make sure your class person() has been declared as public...

    public class person
    {
        ...
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
I shoulda refreshed eh?...  =)
0
 
LVL 18

Expert Comment

by:Ravi Singh
Comment Utility
no worries :)
0
 

Author Comment

by:knowlegde
Comment Utility
It's realy a silly mistake.Thank all. :)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now