CSharpTest.Net
Clear Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IO Namespace > FragmentedFile Class : Clear Method

Glossary Item Box

Destroys all contents of the file and resets to an initial state

Syntax

Visual Basic (Declaration) 
Public Sub Clear() 
C# 
public void Clear()

Example

Library/Library.Test/TestFragmentedFile.cs

C#Copy Code
Dictionary<long, byte[]> data = new Dictionary<long, byte[]>();
using (TempFile file = new TempFile())
using (FragmentedFile ff = FragmentedFile.CreateNew(file.TempPath, 512, 100, 2, FragmentedFile.OptionsDefault))
{
    //Create:
    for (int i = 0; i < 256; i++)
        data.Add(ff.Create(), null);
    //Enumerate:
    int count = 0;
    foreach (KeyValuePair<long, Stream> fragment in ff.ForeachBlock(true, true, null))
        count++;
    Assert.AreEqual(256, count);
    ff.Clear();
    //Empty?
    foreach (KeyValuePair<long, Stream> fragment in ff.ForeachBlock(true, true, null))
        Assert.Fail();
}
VB.NETCopy Code
Dim data As New Dictionary(Of Long, Byte())()
Using file As New TempFile()
    Using ff As FragmentedFile = FragmentedFile.CreateNew(file.TempPath, 512, 100, 2, FragmentedFile.OptionsDefault)
        'Create:
        Dim i As Integer = 0
        While i < 256
            data.Add(ff.Create(), Nothing)
            System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
        End While
        'Enumerate:
        Dim count As Integer = 0
        For Each fragment As KeyValuePair(Of Long, Stream) In ff.ForeachBlock(True, True, Nothing)
            System.Math.Max(System.Threading.Interlocked.Increment(count),count - 1)
        Next
        Assert.AreEqual(256, count)
        ff.Clear()
        'Empty?
        For Each fragment As KeyValuePair(Of Long, Stream) In ff.ForeachBlock(True, True, Nothing)
            Assert.Fail()
        Next
    End Using
End Using

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys