diff --git a/snippets/csharp/System/Array/Clear/Program.cs b/snippets/csharp/System/Array/Clear/Program.cs
new file mode 100644
index 00000000000..a1114d1d20b
--- /dev/null
+++ b/snippets/csharp/System/Array/Clear/Program.cs
@@ -0,0 +1,2 @@
+Example.RunIt();
+Example1.RunIt();
diff --git a/snippets/csharp/System/Array/Clear/Project.csproj b/snippets/csharp/System/Array/Clear/Project.csproj
new file mode 100644
index 00000000000..a269962b552
--- /dev/null
+++ b/snippets/csharp/System/Array/Clear/Project.csproj
@@ -0,0 +1,8 @@
+
+
+
+ Exe
+ net8.0
+
+
+
diff --git a/snippets/csharp/System/Array/Clear/clearstruct1.cs b/snippets/csharp/System/Array/Clear/clearstruct1.cs
index c436b23e1e7..e2b79882941 100644
--- a/snippets/csharp/System/Array/Clear/clearstruct1.cs
+++ b/snippets/csharp/System/Array/Clear/clearstruct1.cs
@@ -3,46 +3,44 @@
public struct TimeZoneTime
{
- private DateTimeOffset dt;
- private TimeZoneInfo tz;
+ public TimeZoneTime(DateTimeOffset dateTime, TimeZoneInfo timeZone)
+ {
+ DateTime = dateTime;
+ TimeZone = timeZone;
+ }
- public TimeZoneTime(DateTimeOffset dateTime, TimeZoneInfo timeZone)
- {
- dt = dateTime;
- tz = timeZone;
- }
+ public DateTimeOffset DateTime { get; }
- public DateTimeOffset DateTime
- { get { return dt; } }
-
- public TimeZoneInfo TimeZone
- { get { return tz; } }
+ public TimeZoneInfo TimeZone { get; }
}
-public class Example
+public class Example1
{
- public static void Main()
- {
- // Declare an array with two elements.
- TimeZoneTime[] timeZoneTimes = { new TimeZoneTime(DateTime.Now, TimeZoneInfo.Local),
- new TimeZoneTime(DateTime.Now, TimeZoneInfo.Utc) };
- foreach (var timeZoneTime in timeZoneTimes)
- Console.WriteLine("{0}: {1:G}",
- timeZoneTime.TimeZone == null ? "" : timeZoneTime.TimeZone.ToString(),
- timeZoneTime.DateTime);
- Console.WriteLine();
+ public static void RunIt()
+ {
+ // Declare an array with two elements.
+ TimeZoneTime[] timeZoneTimes = {
+ new(DateTime.Now, TimeZoneInfo.Local),
+ new(DateTime.Now, TimeZoneInfo.Utc)
+ };
+ foreach (var timeZoneTime in timeZoneTimes)
+ Console.WriteLine("{0}: {1:G}",
+ timeZoneTime.TimeZone == null ? "" : timeZoneTime.TimeZone.ToString(),
+ timeZoneTime.DateTime);
+ Console.WriteLine();
- Array.Clear(timeZoneTimes, 1, 1);
- foreach (var timeZoneTime in timeZoneTimes)
- Console.WriteLine("{0}: {1:G}",
- timeZoneTime.TimeZone == null ? "" : timeZoneTime.TimeZone.ToString(),
- timeZoneTime.DateTime);
- }
+ Array.Clear(timeZoneTimes, 1, 1);
+ foreach (var timeZoneTime in timeZoneTimes)
+ Console.WriteLine("{0}: {1:G}",
+ timeZoneTime.TimeZone == null ? "" : timeZoneTime.TimeZone.ToString(),
+ timeZoneTime.DateTime);
+ }
}
+
// The example displays the following output:
// (UTC-08:00) Pacific Time (US & Canada): 1/20/2014 12:11:00 PM
// UTC: 1/20/2014 12:11:00 PM
//
// (UTC-08:00) Pacific Time (US & Canada): 1/20/2014 12:11:00 PM
// : 1/1/0001 12:00:00 AM
-//
\ No newline at end of file
+//
diff --git a/snippets/csharp/System/Array/Clear/example.cs b/snippets/csharp/System/Array/Clear/example.cs
index e8bd35cb613..fa98a4b766e 100644
--- a/snippets/csharp/System/Array/Clear/example.cs
+++ b/snippets/csharp/System/Array/Clear/example.cs
@@ -3,7 +3,7 @@
class Example
{
- public static void Main()
+ public static void RunIt()
{
Console.WriteLine("One dimension (Rank=1):");
int[] numbers1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
@@ -50,12 +50,12 @@ public static void Main()
Console.WriteLine();
}
- Console.WriteLine("Three dimensions (Rank=3):");
- int[, ,] numbers3 = {{{1, 2}, {3, 4}},
+ Console.WriteLine("\nThree dimensions (Rank=3):");
+ int[,,] numbers3 = {{{1, 2}, {3, 4}},
{{5, 6}, {7, 8}},
{{9, 10}, {11, 12}}};
- for (int i = 0; i < 2; i++)
+ for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 2; j++)
{
@@ -71,7 +71,7 @@ public static void Main()
Console.WriteLine("Array.Clear(numbers3, 2, 5)");
Array.Clear(numbers3, 2, 5);
- for (int i = 0; i < 2; i++)
+ for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 2; j++)
{
@@ -85,6 +85,7 @@ public static void Main()
}
}
}
+
/* This code example produces the following output:
*
* One dimension (Rank=1):
@@ -117,4 +118,4 @@ public static void Main()
* 0 0
* 0 8
*/
-//
\ No newline at end of file
+//
diff --git a/snippets/fsharp/VS_Snippets_CLR_System/system.Array.Clear/fs/example.fs b/snippets/fsharp/VS_Snippets_CLR_System/system.Array.Clear/fs/example.fs
index 36f4678a0f9..2a64ed13883 100644
--- a/snippets/fsharp/VS_Snippets_CLR_System/system.Array.Clear/fs/example.fs
+++ b/snippets/fsharp/VS_Snippets_CLR_System/system.Array.Clear/fs/example.fs
@@ -7,13 +7,13 @@ printfn "One dimension (Rank=1):"
let numbers1 = [| 1..9 |]
for i in numbers1 do
- printf $"{i} "
+ printf $"{i} "
printfn "\n\nArray.Clear(numbers1, 2, 5)"
Array.Clear(numbers1, 2, 5)
for i in numbers1 do
- printf $"{i} "
+ printf $"{i} "
printfn "\n\nTwo dimensions (Rank=2):"
@@ -92,4 +92,4 @@ for i = 0 to 1 do
// 0 0
// 0 8
//
-//
\ No newline at end of file
+//
diff --git a/snippets/visualbasic/VS_Snippets_CLR_System/system.Array.Clear/vb/Program.vb b/snippets/visualbasic/VS_Snippets_CLR_System/system.Array.Clear/vb/Program.vb
new file mode 100644
index 00000000000..7f832d9fdb3
--- /dev/null
+++ b/snippets/visualbasic/VS_Snippets_CLR_System/system.Array.Clear/vb/Program.vb
@@ -0,0 +1,6 @@
+Public Class Program
+ Public Shared Sub Main()
+ Example.RunIt()
+ 'Example1.RunIt()
+ End Sub
+End Class
diff --git a/snippets/visualbasic/VS_Snippets_CLR_System/system.Array.Clear/vb/Project.vbproj b/snippets/visualbasic/VS_Snippets_CLR_System/system.Array.Clear/vb/Project.vbproj
new file mode 100644
index 00000000000..a269962b552
--- /dev/null
+++ b/snippets/visualbasic/VS_Snippets_CLR_System/system.Array.Clear/vb/Project.vbproj
@@ -0,0 +1,8 @@
+
+
+
+ Exe
+ net8.0
+
+
+
diff --git a/snippets/visualbasic/VS_Snippets_CLR_System/system.Array.Clear/vb/clearstruct1.vb b/snippets/visualbasic/VS_Snippets_CLR_System/system.Array.Clear/vb/clearstruct1.vb
index 0b944f9dd03..3628620a1eb 100644
--- a/snippets/visualbasic/VS_Snippets_CLR_System/system.Array.Clear/vb/clearstruct1.vb
+++ b/snippets/visualbasic/VS_Snippets_CLR_System/system.Array.Clear/vb/clearstruct1.vb
@@ -3,46 +3,46 @@
'
Public Structure TimeZoneTime
- Private dt As DateTimeOffset
- Private tz As TimeZoneInfo
-
- Public Sub New(dateTime As DateTimeOffset, timeZone As TimeZoneInfo)
- dt = dateTime
- tz = timeZone
- End Sub
+ Private dt As DateTimeOffset
+ Private tz As TimeZoneInfo
- Public ReadOnly Property DateTime As DateTimeOffset
- Get
- Return dt
- End Get
- End Property
-
- Public ReadOnly Property TimeZone As TimeZoneInfo
- Get
- Return tz
- End Get
- End Property
+ Public Sub New(dateTime As DateTimeOffset, timeZone As TimeZoneInfo)
+ dt = dateTime
+ tz = timeZone
+ End Sub
+
+ Public ReadOnly Property DateTime As DateTimeOffset
+ Get
+ Return dt
+ End Get
+ End Property
+
+ Public ReadOnly Property TimeZone As TimeZoneInfo
+ Get
+ Return tz
+ End Get
+ End Property
End Structure
-Module Example
- Public Sub Main()
- ' Declare an array with two elements.
- Dim timeZoneTimes() As TimeZoneTime = { New TimeZoneTime(Date.Now, TimeZoneInfo.Local),
- New TimeZoneTime(Date.Now, TimeZoneInfo.Utc) }
- For Each timeZoneTime In timeZoneTimes
- Console.WriteLine("{0}: {1:G}",
- If(timeZoneTime.TimeZone Is Nothing, "", timeZoneTime.TimeZone),
+Module Example1
+ Public Sub RunIt()
+ ' Declare an array with two elements.
+ Dim timeZoneTimes() As TimeZoneTime = {New TimeZoneTime(Date.Now, TimeZoneInfo.Local),
+ New TimeZoneTime(Date.Now, TimeZoneInfo.Utc)}
+ For Each timeZoneTime In timeZoneTimes
+ Console.WriteLine("{0}: {1:G}",
+ If(timeZoneTime.TimeZone Is Nothing, "", timeZoneTime.TimeZone),
timeZoneTime.DateTime)
- Next
- Console.WriteLine()
-
- Array.Clear(timeZoneTimes, 1, 1)
- For Each timeZoneTime In timeZoneTimes
- Console.WriteLine("{0}: {1:G}",
- If(timeZoneTime.TimeZone Is Nothing, "", timeZoneTime.TimeZone),
+ Next
+ Console.WriteLine()
+
+ Array.Clear(timeZoneTimes, 1, 1)
+ For Each timeZoneTime In timeZoneTimes
+ Console.WriteLine("{0}: {1:G}",
+ If(timeZoneTime.TimeZone Is Nothing, "", timeZoneTime.TimeZone),
timeZoneTime.DateTime)
- Next
- End Sub
+ Next
+ End Sub
End Module
' The example displays output like the following:
' (UTC-08:00) Pacific Time (US & Canada): 1/20/2014 12:11:00 PM
diff --git a/snippets/visualbasic/VS_Snippets_CLR_System/system.Array.Clear/vb/example.vb b/snippets/visualbasic/VS_Snippets_CLR_System/system.Array.Clear/vb/example.vb
index d16c3ef5aba..abc9ef066bc 100644
--- a/snippets/visualbasic/VS_Snippets_CLR_System/system.Array.Clear/vb/example.vb
+++ b/snippets/visualbasic/VS_Snippets_CLR_System/system.Array.Clear/vb/example.vb
@@ -1,12 +1,12 @@
'
Module Example
- Sub Main()
+ Sub RunIt()
Console.WriteLine(vbLf & "One dimension (Rank=1):")
Dim numbers1() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9}
For i As Integer = 0 To 8
Console.Write("{0} ", numbers1(i))
- Next
+ Next
Console.WriteLine()
Console.WriteLine(vbLf & "Array.Clear(numbers1, 2, 5)")
@@ -14,19 +14,19 @@ Module Example
For i As Integer = 0 To 8
Console.Write("{0} ", numbers1(i))
- Next
+ Next
Console.WriteLine()
Console.WriteLine(vbLf & "Two dimensions (Rank=2):")
- Dim numbers2(,) As Integer = {{ 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }}
+ Dim numbers2(,) As Integer = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
For i As Integer = 0 To 2
For j As Integer = 0 To 2
Console.Write("{0} ", numbers2(i, j))
- Next
+ Next
Console.WriteLine()
- Next
+ Next
Console.WriteLine(vbLf & "Array.Clear(numbers2, 2, 5)")
Array.Clear(numbers2, 2, 5)
@@ -34,69 +34,68 @@ Module Example
For i As Integer = 0 To 2
For j As Integer = 0 To 2
Console.Write("{0} ", numbers2(i, j))
- Next
+ Next
Console.WriteLine()
- Next
-
+ Next
Console.WriteLine(vbLf & "Three dimensions (Rank=3):")
- Dim numbers3(,,) As Integer = {{{ 1, 2 }, { 3, 4 }}, _
- {{ 5, 6 }, { 7, 8 }}, _
- {{ 9, 10 }, { 11, 12 }}}
+ Dim numbers3(,,) As Integer = {{{1, 2}, {3, 4}},
+ {{5, 6}, {7, 8}},
+ {{9, 10}, {11, 12}}}
- For i As Integer = 0 To 1
+ For i As Integer = 0 To 2
For j As Integer = 0 To 1
For k As Integer = 0 To 1
Console.Write("{0} ", numbers3(i, j, k))
- Next
+ Next
Console.WriteLine()
- Next
+ Next
Console.WriteLine()
- Next
- Console.WriteLine()
-
+ Next
+
Console.WriteLine("Array.Clear(numbers3, 2, 5)")
Array.Clear(numbers3, 2, 5)
- For i As Integer = 0 To 1
+ For i As Integer = 0 To 2
For j As Integer = 0 To 1
For k As Integer = 0 To 1
Console.Write("{0} ", numbers3(i, j, k))
- Next
+ Next
Console.WriteLine()
- Next
+ Next
Console.WriteLine()
- Next
+ Next
End Sub
End Module
+
' The example displays the following output:
' One dimension (Rank=1):
' 1 2 3 4 5 6 7 8 9
-'
+'
' Array.Clear(numbers1, 2, 5)
' 1 2 0 0 0 0 0 8 9
-'
+'
' Two dimensions (Rank=2):
' 1 2 3
' 4 5 6
' 7 8 9
-'
+'
' Array.Clear(numbers2, 2, 5)
' 1 2 0
' 0 0 0
' 0 8 9
-'
+'
' Three dimensions (Rank=3):
' 1 2
' 3 4
'
' 5 6
' 7 8
-'
+'
' Array.Clear(numbers3, 2, 5)
' 1 2
' 0 0
-'
+'
' 0 0
' 0 8
-'
\ No newline at end of file
+'
diff --git a/xml/System/Array.xml b/xml/System/Array.xml
index 2730d85f567..8439dc10e5f 100644
--- a/xml/System/Array.xml
+++ b/xml/System/Array.xml
@@ -1298,11 +1298,9 @@
The range of cleared elements wrap from row to row in a multi-dimensional array.
- This method only clears the values of the elements; it does not delete the elements themselves. An array has a fixed size; therefore, elements cannot be added or removed.
-
- This method is an O(`n`) operation, where `n` is `length`.
-
+ This method only clears the values of the elements; it does not delete the elements themselves. An array has a fixed size; therefore, elements can't be added or removed.
+ This method is an $O(n)$ operation, where $n$ is `length`.
## Examples
The following example uses the method to reset integer values in a one-dimensional, two-dimensional, and three-dimensional array.