CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2002
    Location
    Torture chamber
    Posts
    132

    How to I acheve the same effect as &(int) in C#

    In C++, we can do this,
    void SomeFunctions(int &a){...}

    But in C#, I used,
    public SomeFunctions(ref int a) and the compiler says invalid argument.
    i.e.
    ...
    int x=0;
    SomeFunctions(x);
    ...

    Then I tried this,
    public SomeFunction(ref Object a) and the compiler says cannot convert Object from int.
    I thought C# is able to auto-box int to an Object?

    So now, I'm jammed here, how should I proceed?
    end------------------------------
    Programmers aren't born, but are made from hardwork, effort and time.
    To be a good one, requires more effort and hardwork.
    Therefore N quality programmer = (N*hardwork)+(N*effort)+(N*time)

  2. #2
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    no u keep method as it is
    and pass as

    SomeMethodCall(ref a) ;
    like that

    Paresh

  3. #3
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    forgot to mention

    public void DrawAppointment(ref int abc)
    {
    x = x * x;
    }

    would be called as

    int x = 10;
    DrawAppointment(ref x);

    now x will have 100;

    Paresh

  4. #4
    Join Date
    Oct 2002
    Location
    Torture chamber
    Posts
    132
    Oh my GOD! I can't believe I'm making such a careless mistake!

    I called using "someFunctions(x)" where it should be "SomeFunctions(ref x)".

    Thanks for the enlightenment.
    end------------------------------
    Programmers aren't born, but are made from hardwork, effort and time.
    To be a good one, requires more effort and hardwork.
    Therefore N quality programmer = (N*hardwork)+(N*effort)+(N*time)

  5. #5
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    no probs...
    it happens.. but if you are compiling programs then you should check some syntaxes here and there. .since its just matter of testing ... :-)

    Paresh

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured