Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-06-13
5
Medium Priority
?
219 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 300 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

609 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