What's the best way to achieve this, or is this a bad idea?
Feb 12 '07
14 6139
"Peter Bromberg [C# MVP]" <pb*******@yaho o.yabbadabbadoo .coma écrit dans
le message de news: 1D************* *************** **...icrosof t.com...
| Did their homework after all.
| Nice.
| Peter
| "Laura T." wrote:
|
| Supported yes, but also correctly implemented to be really
| readonlycollect ion, for example:
| >
>>>>>>
| So it really remains "immutable" .
Shucks! you saw through my little ploy :-)
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
But ReadoOnlyCollec tionBase is within the System.Collecti ons
namespace, not System.Collecti ons.Generic.
So if I want my immutable list to be Generic, I guess I should
implement ICollection<T>, IEnumerable<T>, ICollection, IEnumerable and
do this by hand?
There is a ReadOnlyCollect ion<Tin one of the system.collecti ons
namespaces. I use it, but don't remember off-hand which namespace.
Mike Ober.
<ph********@gma il.comwrote in message
news:11******** *************@v 33g2000cwv.goog legroups.com...
But ReadoOnlyCollec tionBase is within the System.Collecti ons
namespace, not System.Collecti ons.Generic.
So if I want my immutable list to be Generic, I guess I should
implement ICollection<T>, IEnumerable<T>, ICollection, IEnumerable and
do this by hand?
Yes, it it in the ObjectModel namespace (who knows why).
The only problem with it is that it does not lend for nice inheritance,
because ReadOnlyCollect ion<Thas only one constructor that needs a IList as
a parameter.. it is, afterall, ReadOnly..
"Michael D. Ober" <obermd.@.alum. mit.edu.nospamh a scritto nel messaggio
news:Vv******** ********@newsre ad1.news.pas.ea rthlink.net...
There is a ReadOnlyCollect ion<Tin one of the system.collecti ons
namespaces. I use it, but don't remember off-hand which namespace.
Mike Ober.
<ph********@gma il.comwrote in message
news:11******** *************@v 33g2000cwv.goog legroups.com...
>But ReadoOnlyCollec tionBase is within the System.Collecti ons namespace, not System.Collecti ons.Generic.
So if I want my immutable list to be Generic, I guess I should implement ICollection<T>, IEnumerable<T>, ICollection, IEnumerable and do this by hand?
:-) There is a reason. I had that problem years ago. I was supposed to
implement a static collection so I derived it from ReadOnlyCollect ionBase.
Just a very light wrapper. But I ignored the IList interface..
After a while my collection "had learned" the capability to write too..
That's why when the generic one come out, I was eager to check if they did
the same bad thing as with ReadOnlyCollect ionBase...
As Peter said, the second time, you need to do your homework properly.
"Joanna Carter [TeamB]" <jo****@not.for .spamha scritto nel messaggio
news:u5******** ******@TK2MSFTN GP06.phx.gbl...
"Peter Bromberg [C# MVP]" <pb*******@yaho o.yabbadabbadoo .coma écrit dans
le message de news: 1D************* *************** **...icrosof t.com...
| Did their homework after all.
| Nice.
| Peter
| "Laura T." wrote:
|
| Supported yes, but also correctly implemented to be really
| readonlycollect ion, for example:
| >
>>>>>>>
| So it really remains "immutable" .
Shucks! you saw through my little ploy :-)
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Zalek Bloom |
last post by:
I am learning about difference between String and StringBuffer
classes. In a book it sayes that a String class is immutable, that
means that one an instance of String class is created, the string it
contais cannot be changed, only reference will change to point to a
different string. So results will be different in the following code
depending is a, b are defined as String or StringBuffer:
a = new String("test") (or new...
|
by: Anne Wangnick |
last post by:
Dear all,
I don't get why the index() method is only defined for mutable sequence
types. This is not what I expected. Shouldn't this be added in Python? Is
there such a PEP already?
Regards,
Sebastian Wangnick
|
by: jfj |
last post by:
Yo.
Why can't we __setitem__ for tuples?
The way I see it is that if we enable __setitem__ for tuples there
doesn't seem to be any performance penalty if the users don't use it
(aka, python performance independent of tuple mutability).
On the other hand, right now we have to use a list if we want to
__setitem__ on a sequence. If we could use tuples in the cases where
we want to modify items but not modify the length of the sequence,
|
by: Chris |
last post by:
Hi
Consider the following tuples:
>>> t = (,)
>>> u = (1,2)
>>> v = ('1','2')
>>> t
(, )
>>> u
(1, 2)
|
by: Torsten Mohr |
last post by:
Hi,
reading the documentation (and also from a hint from this NG)
i know now that there are some types that are not mutable.
But why is it this way?
From an overhead point of view i think it is not optimal,
for example for a large string it could be much faster to
have it changed in place, not generating a new one for
| |
by: Andrew Quine |
last post by:
Hi
Just read this article http://www.artima.com/intv/choices.html.
Towards the end of the dicussions, when asked "Did you consider
including support for the concept of immutable directly in C# and the
CLR?" Anders' reply included this comment: "The concept of an
immutable object is very useful, but it's just up to the author to say
that it's immutable."
|
by: Ben Finney |
last post by:
Howdy all,
How can a (user-defined) class ensure that its instances are
immutable, like an int or a tuple, without inheriting from those
types?
What caveats should be observed in making immutable instances?
--
\ "Love is the triumph of imagination over intelligence." -- |
|
by: seberino |
last post by:
Please help me think of an example where immutable tuples are
essential.
It seems that everywhere a tuple is used one could just as easily use
a list instead.
chris
|
by: ssecorp |
last post by:
>>h = "aja baja"
'aja bajae'
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |