Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8398323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:01:27+00:00 2026-06-09T21:01:27+00:00

I have mainly worked in C++ and I am now using C# at my

  • 0

I have mainly worked in C++ and I am now using C# at my new job, and after doing some reading on here about the ‘ref’ keyword and c# value vs reference types I am still finding some confusion with them.

As far as I’m understanding these if you were passing these to a method these would be analogous C++ styles:

Value types:

public void CSharpFunc(value)

and

public void CPlusplusFunc(value)

Reference types:

public void CSharpFunc(reference)

and

public void CPlusPlusFunc(&reference)

‘ref’ / pointer

public void CSharpFunc(ref bar)

and

public void CPlusPlus(*bar)

Is this a correct analogy?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:01:29+00:00Added an answer on June 9, 2026 at 9:01 pm

    Is this a correct analogy?

    Despite what the other answers say, no. What ref means in terms of C++ actually depends on the type. For value types, your assessment is correct (or close enough). For reference types, a more suitable analogy would be a reference-to-pointer:

    public void CPlusPlus(type*& bar)
    

    The whole point about ref is that you can change the reference being passed in. And you can’t do that in C++ by simply passing a pointer:

    void f(type* bar) {
        bar = new_address;
    }
    
    type* x;
    f(x);
    

    This code won’t change the caller’s value of x. If you had passed bar as type*&, on the other hand, it would have changed the value. That is what ref does.

    Furthermore, a reference in C# is quite unlike a reference in C++, and much more like a pointer in C++ (in that you can change which object the reference refers to).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have mainly been using the Exists Method for merging a row into a
I have till now mainly concentrated on web programming thus far and now want
I have a class WorkQueue , just take note about the DoNext() for now,
I have a question about threading in Silverlight. I come mainly from a winForms
I am fairly new to web programming, I have mainly used java to create
I have worked for 5 years mainly in java desktop applications accessing Oracle databases
I have worked with java for a while now, and I found checkstyle to
I am new to c#; I have mainly done Java. I want to implement
I have one website mainly composed on javascript. I hosted it on IIS. This
I want to design a database to store crossword puzzles, mainly I have 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.