What's the best way to achieve this, or is this a bad idea? 14 6138
Hi,
<ph********@gma il.comwrote in message
news:11******** **************@ h3g2000cwc.goog legroups.com...
| What's the best way to achieve this, or is this a bad idea?
Derive from CollectionBase and do not add a Add method. Super easy to
implement.
I do not think it's a bad idea. if you have the need for it .
--
Ignacio Machin
machin AT laceupsolutions com
In 2.0 there is ReadOnlyCollect ion<Twhich does this for you.
Marc
Maybe better yet, derive from ReadOnlyCollect ionBase and you are quite done.
"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions .comha scritto
nel messaggio news:Ol******** ********@TK2MSF TNGP06.phx.gbl. ..
Hi,
<ph********@gma il.comwrote in message
news:11******** **************@ h3g2000cwc.goog legroups.com...
| What's the best way to achieve this, or is this a bad idea?
Derive from CollectionBase and do not add a Add method. Super easy to
implement.
I do not think it's a bad idea. if you have the need for it .
--
Ignacio Machin
machin AT laceupsolutions com
Hi,
"Laura T." <LT@NOWHERE.COM wrote in message
news:u7******** ******@TK2MSFTN GP04.phx.gbl...
| Maybe better yet, derive from ReadOnlyCollect ionBase and you are quite
done.
Yes, you are correct ReadOnlyCollect ionBase is the way to go, Note though
that the only difference is the absence of a Clear method from the readonl
version.
--
Ignacio Machin
machin AT laceupsolutions com
Doesn't the CollectionBase implement the IList interface so it has "extra"
methods like Remove/RemoveAT/Insert, among the other things (so to make it
really read only, you should override those too).
The ReadOnlyCollect ionBase implements only ICollection and IEnumerable so it
does not have them.
"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions .comha scritto
nel messaggio news:e0******** *****@TK2MSFTNG P05.phx.gbl...
Hi,
"Laura T." <LT@NOWHERE.COM wrote in message
news:u7******** ******@TK2MSFTN GP04.phx.gbl...
| Maybe better yet, derive from ReadOnlyCollect ionBase and you are quite
done.
Yes, you are correct ReadOnlyCollect ionBase is the way to go, Note though
that the only difference is the absence of a Clear method from the readonl
version.
--
Ignacio Machin
machin AT laceupsolutions com
"Peter Bromberg [C# MVP]" <pb*******@yaho o.yabbadabbadoo .coma écrit dans
le message de news: 81************* *************** **...icrosof t.com...
| By Jove! Now that there is truly immutable!
....until you cast it to IList, IList<T>, ICollection or ICollection<T>, all
of which are supported by the class. :-)
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
Supported yes, but also correctly implemented to be really
readonlycollect ion, for example:
void IList<T>.Insert (int index, T value) {
ThrowHelper.Thr owNotSupportedE xception(Except ionResource.Not Supported_ReadO nlyCollection);
}
void ICollection<T>. Add(T value) {
ThrowHelper.Thr owNotSupportedE xception(Except ionResource.Not Supported_ReadO nlyCollection);
}
So it really remains "immutable" .
"Joanna Carter [TeamB]" <jo****@not.for .spamha scritto nel messaggio
news:O1******** ******@TK2MSFTN GP03.phx.gbl...
"Peter Bromberg [C# MVP]" <pb*******@yaho o.yabbadabbadoo .coma écrit dans
le message de news: 81************* *************** **...icrosof t.com...
| By Jove! Now that there is truly immutable!
...until you cast it to IList, IList<T>, ICollection or ICollection<T>,
all
of which are supported by the class. :-)
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
Did their homework after all.
Nice.
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Laura T." wrote:
Supported yes, but also correctly implemented to be really
readonlycollect ion, for example:
void IList<T>.Insert (int index, T value) {
ThrowHelper.Thr owNotSupportedE xception(Except ionResource.Not Supported_ReadO nlyCollection);
}
void ICollection<T>. Add(T value) {
ThrowHelper.Thr owNotSupportedE xception(Except ionResource.Not Supported_ReadO nlyCollection);
}
So it really remains "immutable" .
"Joanna Carter [TeamB]" <jo****@not.for .spamha scritto nel messaggio
news:O1******** ******@TK2MSFTN GP03.phx.gbl...
"Peter Bromberg [C# MVP]" <pb*******@yaho o.yabbadabbadoo .coma écrit dans
le message de news: 81************* *************** **...icrosof t.com...
| By Jove! Now that there is truly immutable!
...until you cast it to IList, IList<T>, ICollection or ICollection<T>,
all
of which are supported by the class. :-)
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: 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: 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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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...
| |