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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:04:47+00:00 2026-05-29T21:04:47+00:00

I have a struct TableRow and an array table of such structs: table =

  • 0

I have a struct TableRow and an array table of such structs:

table = new TableRow[10];

Now I want to find and manipulate the content of one of the structs in the array.
I use Array.Find to search the right array element:

var tr = Array.Find( table, tRow => tRow.color == 'red' );
tr.count++;

Problem is that structs are value types and so the Find method returns a copy of the struct that I want to manipulate. Changing this copy does not change the struct in the array.

I can’t seem to find any way to instruct the Find method to return the struct by reference.

  • 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-29T21:04:48+00:00Added an answer on May 29, 2026 at 9:04 pm

    You can’t change the way Find() works for value types. You can either convert your struct to a class — typically we only use struct for very small (<= 16 byte) value types that represent a “single” value anyway. MSDN has good guidance on struct vs class here: Chossing Between Classes and Structs

    Or you can use FindIndex() to get the position in the array, and then use that to modify the field.

    var pos = Array.FindIndex(table, tRow => tRow.color == 'red');
    
    if (pos >= 0)
    {
        table[pos].count++
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's I have struct Vector { float i,j,k; } I want to zero all
Suppose I have: struct Foo: public Bar { .... } Foo introduces no new
I have a struct member that holds lots of string elements. What I want
I have a struct with some fields. One of the fields is of a
Assume i have struct node{ int val; node* left; }; Now, I have a
I have some struct that I need to print frequently. For now, I am
Ok so I have struct like this typedef struct { float x; float y;
Suppose I have: struct Magic { Magic(Foo* foo); Magic(Bar* bar); }; Is there a
In my driver's file_operations structure, I have: struct file_operations Fops = { read: device_read,
I'm using LLVM-clang on Linux. Suppose in foo.cpp I have: struct Foo { int

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.