What am I doing wrong!? Properties!
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: What am I doing wrong!? Properties!

  1. #1
    Join Date
    Dec 2009
    Posts
    48

    Arrow What am I doing wrong!? Properties!

    I have something like this in my code

    class X
    {
    public int age{set; get;}
    public string name {set; get;}
    }


    class Y
    {
    x person = new x();
    int AGE = person.age // <------- Can't I write this?? Visual Studio doesnt recognize the property
    string NAME = person.name // <-- This one doesn't work to!!
    }

    some help here!!
    Maybe I'm just to sleepy to spot the error... but it seems to me it's every thing okay.
    Thank you for your time!!

  2. #2
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: What am I doing wrong!? Properties!

    Can you post your actual code between [ code ] and [ /code ] tags (no spaces in tags) and tell us the exact error. Not sure what you mean by "Doesn't recognise".

    Class X should be public and "X" is not the same as "x" etc etc. Please post your actual code and I'm sure we'll help you sort it out...
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  3. #3
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: What am I doing wrong!? Properties!

    I think the problem is that class X is not public.

  4. #4
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: What am I doing wrong!? Properties!

    Danny is right, you should have received the error which tells this.
    Regards,
    Ramkrishna Pawar

  5. #5
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: What am I doing wrong!? Properties!

    class X does not have to be public if both are in the same assembly.

    and the bug is, that you cannot initialize non-static fields like that. you need to do it in a constructor.

    Code:
    class Y
        {
            X person = new X();
            int AGE;
            string NAME;
            Y()
            {
                // person = new X(); // or here
                AGE = person.age;
                NAME = person.name;
            }
        }
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  6. #6
    Join Date
    Dec 2009
    Posts
    48

    Re: What am I doing wrong!? Properties!

    Think I got it, no more error! works like a charm!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center