I have noticed that there is ...
-
an integer is a value type (in .NET sense). this would mean that you can't change an integer. if you follow the same logic this should be illegal:
System.Drawing.Rectangle rc = new System.Drawing.Rectangle(5, 10, 15, 20); rc.Offset(1,2);
if i can offset a rectangle this way, it should also be possible to do it inside foreach statement.Zdeslav Vojkovic wrote: if i can offset a rectangle this way, it should also be possible to do it inside foreach statement. It is :-)
Rectangle[] rectangles = new Rectangle[2];
rectangles[0] = new Rectangle(5, 10, 15, 20);
rectangles[1] = new Rectangle(5, 10, 15, 20);foreach (Rectangle rc in rectangles)
{
rc.Offset(1,2);
}rc does not reference a copy of rectangle[n], it references the actual Rectangle instance at the current iterator position. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
-
Why do you exclude web application development from that? ASP.NET with C# is like an orgasm on tap.
Ðavid Wulff The Royal Woofle Museum
Audioscrobbler :: flikrDie Freiheit spielt auf allen Geigen
You are correct. I meant windows application development in the generic sense - to include both windows and web programming for microsoft centric solutions. "The Yahoos refused to be tamed."
-
You are correct. I meant windows application development in the generic sense - to include both windows and web programming for microsoft centric solutions. "The Yahoos refused to be tamed."
Ah, ok.
Ðavid Wulff The Royal Woofle Museum
Audioscrobbler :: flikrDie Freiheit spielt auf allen Geigen
-
:omg: No, not French, please. My wife tried to teach me (she has a BA in French) but I just couldn't get any of it. No, I prefer Italian - both the language and food :cool:
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
-
Zdeslav Vojkovic wrote: if i can offset a rectangle this way, it should also be possible to do it inside foreach statement. It is :-)
Rectangle[] rectangles = new Rectangle[2];
rectangles[0] = new Rectangle(5, 10, 15, 20);
rectangles[1] = new Rectangle(5, 10, 15, 20);foreach (Rectangle rc in rectangles)
{
rc.Offset(1,2);
}rc does not reference a copy of rectangle[n], it references the actual Rectangle instance at the current iterator position. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
jan larsen wrote: rc does not reference a copy of rectangle[n], it references the actual Rectangle instance at the current iterator position. no, it does not because Rectangle is a value type, so rc inside foreach is the boxed copy. the original instances in rectangles array remain unchanged, you can check in the debuger. you need this to change them:
int c = 0; foreach (Rectangle rc in rectangles) { rc.Offset(1,2); rectangles[c] = rc; c++; // no pun intended :) }
-
:omg: No, not French, please. My wife tried to teach me (she has a BA in French) but I just couldn't get any of it. No, I prefer Italian - both the language and food :cool:
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
Nemanja Trifunovic wrote: I prefer Italian Both languages aren't that far... Nemanja Trifunovic wrote: food Agreed! :drool: I would also mention women, but perhaps your wife is online too? :rolleyes:
Fold With Us! Chaos A.D. Disorder unleashed
-
Nemanja Trifunovic wrote: I prefer Italian Both languages aren't that far... Nemanja Trifunovic wrote: food Agreed! :drool: I would also mention women, but perhaps your wife is online too? :rolleyes:
Fold With Us! Chaos A.D. Disorder unleashed
K(arl) wrote: Both languages aren't that far... True, but they feel veery different. Italian is much more "Slavic-friendly" - it has only a couple of sounds that Serbian does not. French sounds like a music to me, but when I tried to actually learn it I got frustrated very quickly. K(arl) wrote: I would also mention women, but perhaps your wife is online too? LOL. I don't think she visits Soapbox. Anyway, Italian women I know are a little bit too loud for my taste.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
-
jan larsen wrote: rc does not reference a copy of rectangle[n], it references the actual Rectangle instance at the current iterator position. no, it does not because Rectangle is a value type, so rc inside foreach is the boxed copy. the original instances in rectangles array remain unchanged, you can check in the debuger. you need this to change them:
int c = 0; foreach (Rectangle rc in rectangles) { rc.Offset(1,2); rectangles[c] = rc; c++; // no pun intended :) }
Hmm.., I take you word for it, and I admit that it's a mess that value types can so easily be confused with reference types. Operator
new
should be limited to creating objects on the heap. But still, I don't find System.Collections inferior to STL, on the contrary. To provide a ready library of collections, is a convenience, not something that really adds to the language itself. And I really don't find that STL is more convenient to use than System.Collections. First of all, STL is quite counter-intuitive to use, and secondly, they failed to provide one of my favorites, a hashtable. I can't remember a single larger project where I didn't use a hashtable, so if I was forced to use C++, I would have to implement my own hashtable. Now, I got a book on STL that states 'and it's easy to do using the existing collection templates'. Right, but the bloody idea was that I should use 'standard' templates as the S and T in STL indicates. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus -
Hmm.., I take you word for it, and I admit that it's a mess that value types can so easily be confused with reference types. Operator
new
should be limited to creating objects on the heap. But still, I don't find System.Collections inferior to STL, on the contrary. To provide a ready library of collections, is a convenience, not something that really adds to the language itself. And I really don't find that STL is more convenient to use than System.Collections. First of all, STL is quite counter-intuitive to use, and secondly, they failed to provide one of my favorites, a hashtable. I can't remember a single larger project where I didn't use a hashtable, so if I was forced to use C++, I would have to implement my own hashtable. Now, I got a book on STL that states 'and it's easy to do using the existing collection templates'. Right, but the bloody idea was that I should use 'standard' templates as the S and T in STL indicates. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian GrausI still prefer STL because it's type safe and it is much more than just collections, algorithms and IO/streams are equally important as collection classes, and iterators are something that makes the difference between good and bad collection implementation. it seems that microsoft also thinks that STL is superior since the whole use case for generics in 2.0 is to replace current collections, because generics are not quite suitable for other stuff like templates. OTOH, i completely agree that lack of hashtable in STL is serious omission, but many STL implementations have it included (SGI, STLport). vector is an abomination which is really not a vector at all. string implementation could also be much more user friendly, i much prefer CString.
-
I still prefer STL because it's type safe and it is much more than just collections, algorithms and IO/streams are equally important as collection classes, and iterators are something that makes the difference between good and bad collection implementation. it seems that microsoft also thinks that STL is superior since the whole use case for generics in 2.0 is to replace current collections, because generics are not quite suitable for other stuff like templates. OTOH, i completely agree that lack of hashtable in STL is serious omission, but many STL implementations have it included (SGI, STLport). vector is an abomination which is really not a vector at all. string implementation could also be much more user friendly, i much prefer CString.
I agree that the STL is more powerfull, but I find the templates awkward to use. I think that the generics in 2.0 are way easier to handle. Zdeslav Vojkovic wrote: OTOH, i completely agree that lack of hashtable in STL is serious omission, but many STL implementations have it included (SGI, STLport). Yeah, but the important word to remember is Standard. Why is it better to use std::list intstead of JanLarsen::list if it's not important that I use JanLarsen::hashtable instead of the non-existant std::hashtable? Don't get me wrong, I'm not trying to glorify System.Collections, eg. I still sometimes misses a LinkedList implementation. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
-
I agree that the STL is more powerfull, but I find the templates awkward to use. I think that the generics in 2.0 are way easier to handle. Zdeslav Vojkovic wrote: OTOH, i completely agree that lack of hashtable in STL is serious omission, but many STL implementations have it included (SGI, STLport). Yeah, but the important word to remember is Standard. Why is it better to use std::list intstead of JanLarsen::list if it's not important that I use JanLarsen::hashtable instead of the non-existant std::hashtable? Don't get me wrong, I'm not trying to glorify System.Collections, eg. I still sometimes misses a LinkedList implementation. "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
jan larsen wrote: I agree that the STL is more powerfull, but I find the templates awkward to use. I think that the generics in 2.0 are way easier to handle. i'm not sure about that. i didn't have the chance to use them but from what i read it is not possible to do something like this:
public static T Sum(List<T> list) { T sum=0; for(int i=0;i < list.Count;i++) sum+=list[i]; return sum; }
because nonconstrained types are treated as Objects, and they don't provide + operator. you have to mess with all sorts of workarounds, providing interfaces for simply adding two objects (not necessary numbers). also, the syntax for defining type constraints in generics is, IMHO, horrible and mostly redundant. having to write this:class Something<T> where T: new() { .... }
look like a joke to me jan larsen wrote: Yeah, but the important word to remember is Standard. Why is it better to use std::list intstead of JanLarsen::list if it's not important that I use JanLarsen::hashtable instead of the non-existant std::hashtable? i agree with you on this 200%