?
Solved

How to clear byte array?

Posted on 2004-10-03
3
Medium Priority
?
10,934 Views
Last Modified: 2008-01-09
Is there any elegant way to empty an array in c#? I noticed that in the past there was a .clear method, but now notihing like that exists. (The only way to empty an array I found out is to create new variable which is empty and assign it ot the old one (and hope the old one will be garbage collected))

Thank you!
0
Comment
Question by:ssdjgru1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
AvonWyss earned 500 total points
ID: 12215164
Lists have .Clear() methods, but Arrays do not. You need to overwrite each single value if you want to reset the array. Your way of assigning a newly created array is just fine; also, most of the time there is no need at all to have the array initialized in the first place!
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 12215426
You can replace the old array by an empty array:

// initialize array:
string[] myArray = new string[]{"Hello", "World!"}:

// 'clear' array:
myArray = new string[0];  // the old instance will be deleted by the garbage collection
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 12215477
Thank you - the points from this Q just made me a Certified C# Guru Expert... ;-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question