Skip to content

Commit

Permalink
fix loop counter and add project files
Browse files Browse the repository at this point in the history
  • Loading branch information
gewarren committed Jan 8, 2025
1 parent 55df97b commit 883b99e
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 107 deletions.
2 changes: 2 additions & 0 deletions snippets/csharp/System/Array/Clear/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Example.RunIt();
Example1.RunIt();
8 changes: 8 additions & 0 deletions snippets/csharp/System/Array/Clear/Project.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

</Project>
58 changes: 28 additions & 30 deletions snippets/csharp/System/Array/Clear/clearstruct1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? "<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 ? "<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 ? "<null>" : timeZoneTime.TimeZone.ToString(),
timeZoneTime.DateTime);
}
Array.Clear(timeZoneTimes, 1, 1);
foreach (var timeZoneTime in timeZoneTimes)
Console.WriteLine("{0}: {1:G}",
timeZoneTime.TimeZone == null ? "<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
// <null>: 1/1/0001 12:00:00 AM
// </Snippet2>
// </Snippet2>
13 changes: 7 additions & 6 deletions snippets/csharp/System/Array/Clear/example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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++)
{
Expand All @@ -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++)
{
Expand All @@ -85,6 +85,7 @@ public static void Main()
}
}
}

/* This code example produces the following output:
*
* One dimension (Rank=1):
Expand Down Expand Up @@ -117,4 +118,4 @@ public static void Main()
* 0 0
* 0 8
*/
//</snippet1>
//</snippet1>
Original file line number Diff line number Diff line change
Expand Up @@ -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):"

Expand Down Expand Up @@ -92,4 +92,4 @@ for i = 0 to 1 do
// 0 0
// 0 8
//
//</snippet1>
//</snippet1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Public Class Program
Public Shared Sub Main()
Example.RunIt()
'Example1.RunIt()
End Sub
End Class
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,46 @@

' <Snippet2>
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, "<null>", 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, "<null>", 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, "<null>", 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, "<null>", 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,102 +1,101 @@
' <Snippet1>
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)")
Array.Clear(numbers1, 2, 5)

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)

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
' </Snippet1>
' </Snippet1>
Loading

0 comments on commit 883b99e

Please sign in to comment.