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

  • Home
  • SEARCH
  • 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 6880211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:56:44+00:00 2026-05-27T04:56:44+00:00

Take a look at the following example: public void inc(int num) { num++; }

  • 0

Take a look at the following example:

public void inc(int num) {
   num++;
}

int a = 5;
inc(a);

In this case, inc won’t increment the a variable itself. It is not pointing to the same location in the memory. In order to change a, I’ll have to use ref.

However, in this example

public static void ExportSelectedRow(GridView gridView, object toObject, int skipCols)
{
    GridViewRow gridViewRow = gridView.SelectedRow;

    if (toObject is DataTable)
    {
        DataTable returnDt = (DataTable)toObject;
        GridViewColsToDatatable(gridView, returnDt, skipCols);
        DataRow dr = returnDt.NewRow();
        for (int i = skipCols; i < gridViewRow.Cells.Count; i++)
            dr[i - skipCols] = gridViewRow.Cells[i].Text;
        returnDt.Rows.Add(dr);
    }

}

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) {
    DataTable dt = new DataTable();
    GridViewHelper.ExportSelectedRow(GridView1, dt, 1);
    ...
}

the selected row will be exported from the GridView1 into DataTable although I didn’t even referenced it in the function. So the toObject will be updated. It seems that

DataTable returnDt = (DataTable)toObject;

is actually referencing to the toObject. So my question, why in this example it is a reference, but in the first one, it is not?

  • 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-05-27T04:56:45+00:00Added an answer on May 27, 2026 at 4:56 am

    Contrary to what other people are going to say, by default everything (yes also reference types) in C# is passed by value. With ref or out they aren’t.
    But in the case of reference types, the thing that is passed by value is a reference.

    int is of course a value type, DataTable is a reference type.

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

Sidebar

Related Questions

take a look at this example code: public class Comment { private Comment() {
Take a look at this code: public class Test { public static void main(String...
Please, take a look at this example: import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Test
Please take a look on the following example: class Base { protected: int m_nValue;
please take a look at the following snippet: public IEnumerable<T> Query(Expression<Func<T, bool>> filter) {
Take a look at this example, and notice the outputs indicated. <?php class Mommy
Please take a look at the following example: http://jsfiddle.net/MVfVD/ I want the overlayedFrameFooter div
For example take the following class: class GameBoard { public double Evaluate(PieceType cpusPieceType) {
Take a look that the following code snippet: A a = null try {
Please take a look at the following .htaccess ErrorDocument 404 /404/ RewriteEngine On RewriteRule

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.