473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

error very strange

a function, whose parameter is a ref to a collection of class I
private void func(List<Ii){
for(int n=0;n<MAXVALUE;++n){

for(int m=0;m<MAXVALUE;++m){

Dosomething();
}

i[n].value=5; [******]Eror: can't modify the value of
System.Collections.Generic.List<program.Form1.I>.t his[int] because it
is not a variable[/******]
}
Thanks

Nov 13 '06 #1
4 1109
Any questions or answers ? Looks like nobody is in now.

Argentino Douglas wrote:
a function, whose parameter is a ref to a collection of class I
private void func(List<Ii){
for(int n=0;n<MAXVALUE;++n){

for(int m=0;m<MAXVALUE;++m){

Dosomething();
}

i[n].value=5; [******]Eror: can't modify the value of
System.Collections.Generic.List<program.Form1.I>.t his[int] because it
is not a variable[/******]
}
Thanks
Nov 13 '06 #2
Argentino Douglas <do*******************@yahoo.com.arwrote:
a function, whose parameter is a ref to a collection of class I
private void func(List<Ii){
for(int n=0;n<MAXVALUE;++n){

for(int m=0;m<MAXVALUE;++m){

Dosomething();
}

i[n].value=5; [******]Eror: can't modify the value of
System.Collections.Generic.List<program.Form1.I>.t his[int] because it
is not a variable[/******]
}
Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 13 '06 #3
public struct I{
public int value;
}

private void ValuableHelper(List<I>i){

i=new List<I>();

for(int n=0;n<MAXVALUE;++n){

for(int m=0;m<MAXVALUE;++m){

PleaseHelpMe();

}

i[n].value=5; //Error is here

}
}
I am coding it as a window application,
Thanks
Jon Skeet [ C# MVP ] wrote:
Argentino Douglas <do*******************@yahoo.com.arwrote:
a function, whose parameter is a ref to a collection of class I
private void func(List<Ii){
for(int n=0;n<MAXVALUE;++n){

for(int m=0;m<MAXVALUE;++m){

Dosomething();
}

i[n].value=5; [******]Eror: can't modify the value of
System.Collections.Generic.List<program.Form1.I>.t his[int] because it
is not a variable[/******]
}

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 13 '06 #4
Argentino Douglas <do*******************@yahoo.com.arwrote:
public struct I{
public int value;
}

private void ValuableHelper(List<I>i){

i=new List<I>();

for(int n=0;n<MAXVALUE;++n){

for(int m=0;m<MAXVALUE;++m){

PleaseHelpMe();

}

i[n].value=5; //Error is here

}
}
I am coding it as a window application,
Well, firstly, that's *not* a short but complete program. Please read
http://www.pobox.com/~skeet/csharp/incomplete.html

However, the cause of your problem is that you've got a struct - a
value type - and you're trying to change a value which is returned from
an indexer. You can't do that, and even if you did, it wouldn't do what
you wanted it to.

i[n] returns a value. If you modify that value, it won't change the
contents of the list at all.

Now, if I were a reference type, you'd be modifying the value *referred
to* by the reference in the list, and that would be a different matter.

This kind of problem is just one reason why mutable value types are
generally a bad idea.

Oh, and regards your other post: you can't expect replies *that*
quickly. You only left your original message for 9 minutes before
posting again!

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 13 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: grundmann | last post by:
Hello, i got a strange compiler error. When compiling the following: // forward declarations typedef AvlTree<LineSegment,LineSegmentComperator> LSTree; void handleEventPoint (const...
0
by: Kris Vanherck | last post by:
yesterday i started getting this strange error when i try to run my asp.net project: Compiler Error Message: CS0006: Metadata file 'c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net...
5
by: Nathan Sokalski | last post by:
When I view my index.aspx page any time after the first time, I recieve the following error: System.Web.TraceContext.AddNewControl(String id, String parentId, String type, Int32 viewStateSize)...
3
by: Randy | last post by:
Hello All, I'm getting a strange error when trying to perform a file upload. Here's the lines that uploads the file... sSaveLocation = Server.MapPath("PFPDocs") + "\\" + fileName;...
5
by: Shapper | last post by:
Hello, I just upload my web site to my hosting server and when I access it I always get an error: "Redicterion limit for this URL exceeded. Unable to load the requested page" Does anyone...
3
by: Eric | last post by:
I am getting a strange error on one of my pages using Linkbuttons. The linkbutton works once. After the page is posted, I get a strange JavaScript error: "Error: 'undefined' is null or not an...
6
by: Raul Rodriguez | last post by:
I posted this question already but nobody could answer me. Please forgive for doing it again, but it's very important for my company. We have been searching for this error with different engines...
11
by: Martin Joergensen | last post by:
Hi, I've encountered a really, *really*, REALLY strange error :-) I have a for-loop and after 8 runs I get strange results...... I mean: A really strange result.... I'm calculating...
11
by: Mike C# | last post by:
Hi all, I keep getting a strange error and can't pin it down. The message is: This application has requested the Runtime to terminate it in an unusual way. Please contact the application's...
2
by: Paolo | last post by:
Hi to all, I have an error that drove me crazy. Try the following page that should only allow to upload a file: <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.