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 8057893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:10:47+00:00 2026-06-05T09:10:47+00:00

Possible Duplicate: Read-only (“const”-like) function parameters of C# Why is there no const member

  • 0

Possible Duplicate:
Read-only (“const”-like) function parameters of C#
Why is there no const member method in C# and const parameter?

Having programmed in C++ in the past, I recall we could make a constant reference/pointer parameter in a method.

If my memory is correct, the below means, that the method cannot alter the reference and the reference itself is a constant reference.

C++ example

void DisplayData(const string &value) const
{
   std::count << value << endl;
}

Is there an equivalent in C# for methods in a class?

The reason why I’m asking is, I’m trying to pass a object by reference (for speed) and at the same time don’t want anyone to alter it.

  • 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-05T09:10:49+00:00Added an answer on June 5, 2026 at 9:10 am

    Update 16/09/2020

    There now appears to be the in parameter modifier that exhibits this behaviour (in essence, a ref readonly). A brief search on when you would ever use this yields the following answer:

    Why would one ever use the "in" parameter modifier in C#?

    Original Answer

    There is no equivalent for C# and it has been asked many, many, many, many times before.

    If you don’t want anyone to alter the "reference", or perhaps you mean the content of the object, make sure the class doesn’t expose any public setters or methods of mutating the class. If you cannot change the class, have it implement an interface that only publicly exposes the members in a read-only fashion and pass the interface reference instead.

    If you mean you want to stop the method from changing the reference, then by default if you pass it "by reference", you are actually passing the reference by value. Any attempt from the method to change what the reference points to will only affect the local method copy, not the caller’s copy. This can be changed by using the ref keyword on a reference type, at which point the method can point the reference at a new underlying object and it will affect the caller.

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

Sidebar

Related Questions

Possible Duplicate: Why would one mark local variables and method parameters as “final” in
Possible Duplicate: How many lines of code should a function/procedure/method have? I would like
Possible Duplicate: Thread safety of std::map for read-only operations Having std::map a can we
Possible Duplicate: Can Read-Only Properties be Implemented in Pure JavaScript? I have an Object
Possible Duplicate: Only read limited number of columns in R I have a data
Possible Duplicate: Enable GPS programatically like Tasker Ok, I know there is same question
Possible Duplicate: Creating an “object” of an interface I am new to Java. Based
Possible Duplicate: What is the difference between const and readonly? i have doubt in
Possible Duplicate: Download PDF from url and read it I have to download a
Possible Duplicate: mmap() vs. reading blocks I heard (read it on the internet somewhere)

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.