473,396 Members | 1,760 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,396 software developers and data experts.

Clear Method

Is there a common defintion of Clear that applies to both
objects and collections? If so, where is it documented.

My preconceived notion is that Clear means "reset the
object to its initial state" and this applies to both
collections and objects. The problem is that I cannot
find anything in the literature supporting this. That
would be ok, but I cannot find anything at all.
Jul 21 '05 #1
5 2294
Clear is a method native to the collectionbase class...everything inherited
from it can implement it. It's actually an implementation of the
IList.Clear interface.
Here's a link about CollecitonBase
http://msdn.microsoft.com/library/de...cleartopic.asp

Not all objects have a Clear method, and in many instances it wouldn't make
sense to have one. What's the difference? Well, I could have an object
like a DataTable comprised of Rows and Columns which are both collections.
in this instance, dt.Clear is a default for dt.Rows.Clear....it doesn't
clear out the columns..although one might argue it should . In this sense,
I have a datatable, add rows and columns, populate it with data, then call
clear, I still have rows. IF I was setting it back to its original state,
I'd have neither.

HTH
"William Schubert" <bs*******@msn.com> wrote in message
news:0b****************************@phx.gbl...
Is there a common defintion of Clear that applies to both
objects and collections? If so, where is it documented.

My preconceived notion is that Clear means "reset the
object to its initial state" and this applies to both
collections and objects. The problem is that I cannot
find anything in the literature supporting this. That
would be ok, but I cannot find anything at all.

Jul 21 '05 #2
William,
To the best of my knowledge Clear is only used in Collections to remove all
the contained items. Not necessarily to an initial state. In that the
collection may have an initial capacity, but Clear does not return the
collection (internally) back to this initial capacity.

My problem with Clear applying to objects, is that on a lot of objects other
than creating a new instance of said object there is not clear 'initial
state' (no pun intended). As you are duplicating logic in the Clear method &
the constructor (yes I would hope both call the same routine). However there
are object that do have a concept of Clear, see MSDN index note below.

You could check the "Design Guidelines for Class Library developers" to see
if there is another definition for Clear.

http://msdn.microsoft.com/library/de...Guidelines.asp

Or you could use the MSDN Index to look up the Clear method and see where
all its applied. Of course you need to hit the one dealing with the .NET
Framework. ;-)

Hope this helps
Jay

"William Schubert" <bs*******@msn.com> wrote in message
news:0b****************************@phx.gbl...
Is there a common defintion of Clear that applies to both
objects and collections? If so, where is it documented.

My preconceived notion is that Clear means "reset the
object to its initial state" and this applies to both
collections and objects. The problem is that I cannot
find anything in the literature supporting this. That
would be ok, but I cannot find anything at all.

Jul 21 '05 #3
Jay:

Agreed, I probably muddled my point. He had asked about the initial state
thing and I guess what I was trying to say is that everything has an
initials state when you just declare and instantiate it. It makes a lot
of sense to have a Clear with collections, but like a Winform or something,
Clear woudln't make much sense. Tons of other objects, like
FileSystemWatcher, CrystalReport etc wouldn't be very good candidates for
clear. However, if they have properties that are collections, then those
would always be good candidates. Ultimately, I was trying to make the point
that Clearing to the initial state would be a big problem in many cases.

As an aside, muchos gracias for the Design Guidelines link....I defnintely
need to take a gander it.

Thanks again,

Bill
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:uH*************@tk2msftngp13.phx.gbl...
William,
To the best of my knowledge Clear is only used in Collections to remove all the contained items. Not necessarily to an initial state. In that the
collection may have an initial capacity, but Clear does not return the
collection (internally) back to this initial capacity.

My problem with Clear applying to objects, is that on a lot of objects other than creating a new instance of said object there is not clear 'initial
state' (no pun intended). As you are duplicating logic in the Clear method & the constructor (yes I would hope both call the same routine). However there are object that do have a concept of Clear, see MSDN index note below.

You could check the "Design Guidelines for Class Library developers" to see if there is another definition for Clear.

http://msdn.microsoft.com/library/de...Guidelines.asp
Or you could use the MSDN Index to look up the Clear method and see where
all its applied. Of course you need to hit the one dealing with the .NET
Framework. ;-)

Hope this helps
Jay

"William Schubert" <bs*******@msn.com> wrote in message
news:0b****************************@phx.gbl...
Is there a common defintion of Clear that applies to both
objects and collections? If so, where is it documented.

My preconceived notion is that Clear means "reset the
object to its initial state" and this applies to both
collections and objects. The problem is that I cannot
find anything in the literature supporting this. That
would be ok, but I cannot find anything at all.


Jul 21 '05 #4
Hi William,

Do you think the posts from William Ryan and Jay B. Harlow answer your
questions?

If you have any Qs, please reply to this post.

--
Parker Zhang
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 21 '05 #5
Actually, not entirely. Upon reading the definintions of
a large number of the clear methods in the framework, I
see threee basic categories:
1. Clear releases the resources for the object
2. Clear resets the object to an initial state
3. Clear removes all elements of the collection, but
does not appear to reset the state. (Clear is a big part
of CollectionBase derived classes, as one would suspect.)

My coworker's concern was that he believed that a call
to "Clear()" on a collection associated with a database,
followed by a save, should essentially remove all the
associated records from the database. Essentially,
Clear() = RemoveAll(). Thus he believes the meaning
of "Clear()" is not consistent among the objects in
the .Net framework.

My impression was that "Clear()" was used to reset the
object to an initial state, so I use "Clear()" in my
configuration application when changing tasks, or prior
to exit, much as the DOS command CLS was used when I was
much younger. If Clear means "reset the object to an
initial state", then IList.Clear() is essentially the
same as Graphics.Clear() or CryptoStream.Clear().

The result of the confusion, as you might expect, is an
application that raises the "I am dirty, do you want to
save?" message, and if the user selects "Yes", all the
records in the database are deleted! Thus we require
some clarification (believe me, I am trying to be careful
not to use the word "Clear" here) as to whether or not
there is a generalized definition and usage for this
method call.

Thank you to all for the clarifications to date.
Hi William,

Do you think the posts from William Ryan and Jay B. Harlow answer yourquestions?

If you have any Qs, please reply to this post.

Jul 21 '05 #6

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

Similar topics

19
by: Dave | last post by:
Hi, I have done some research, trying to Clear The Screen in java code. The first option was the obv: system.out.print("\n\n\n\n\n\n\n\n\n\n\n\n"); then i heard about this method:...
2
by: Tomomichi Amano | last post by:
Hello How can I delete (clear) lines that were made useing Graphics.DrawLine() ? Thanks in advance! Have a nice day!
4
by: Raterus | last post by:
Howdy, Simple question, but I can't figure out how to do it. I have a a page which is called initially with a querystring. After I get the querystring values, I don't need the querystring to...
5
by: William Schubert | last post by:
Is there a common defintion of Clear that applies to both objects and collections? If so, where is it documented. My preconceived notion is that Clear means "reset the object to its initial...
0
by: Flack | last post by:
I have pasted at the end of this message a small sample program I whipped up to do some testing. It's a form with a datagrid and two buttons. Each button clears the dataTable that is the source...
77
by: Ville Vainio | last post by:
I tried to clear a list today (which I do rather rarely, considering that just doing l = works most of the time) and was shocked, SHOCKED to notice that there is no clear() method. Dicts have it,...
4
by: matt | last post by:
hello, so from time to time i have to write code to send a file or a stream back to the end user. in my mini library i have code to do so. however, some of the Response object properties arent...
18
by: Marko.Cain.23 | last post by:
Hi, I create a dictionary like this myDict = {} and I add entry like this: myDict = 1 but how can I empty the whole dictionary? Thank you.
32
by: =?Utf-8?B?U2l2?= | last post by:
I have a form that I programmatically generate some check boxes and labels on. Later on when I want to draw the form with different data I want to clear the previously created items and then put...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
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...
0
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...
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...

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.