Skip to content

Commit e2c13bc

Browse files
authored
Improve array init (#11844)
1 parent a372975 commit e2c13bc

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

snippets/csharp/System.Xml.Serialization/XmlSerializer/FromTypes/Project.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Library</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net9.0</TargetFramework>
66
</PropertyGroup>
7-
8-
</Project>
7+
8+
</Project>

snippets/csharp/System.Xml.Serialization/XmlSerializer/FromTypes/source.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,24 @@ public class Test
2525
{
2626
public static void Main()
2727
{
28-
Test t = new Test();
28+
Test t = new();
2929
t.GetSerializers();
3030
}
3131

3232
public void GetSerializers()
3333
{
3434
// Create an array of types.
35-
Type[]types = new Type[3];
36-
types[0] = typeof(Instrument);
37-
types[1] = typeof(Player);
38-
types[2] = typeof(Piece);
35+
Type[] types = [typeof(Instrument), typeof(Player), typeof(Piece)];
3936

4037
// Create an array for XmlSerializer objects.
41-
XmlSerializer[]serializers= new XmlSerializer[3];
38+
XmlSerializer[] serializers = new XmlSerializer[3];
4239
serializers = XmlSerializer.FromTypes(types);
4340
// Create one Instrument and serialize it.
4441
Instrument i = new Instrument();
4542
i.InstrumentName = "Piano";
4643
// Create a TextWriter to write with.
4744
TextWriter writer = new StreamWriter("Inst.xml");
48-
serializers[0].Serialize(writer,i);
45+
serializers[0].Serialize(writer, i);
4946
writer.Close();
5047
}
5148
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>

snippets/visualbasic/System.Xml.Serialization/XmlSerializer/FromTypes/source.vb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
Imports System.IO
33
Imports System.Xml.Serialization
44

5-
65
' Three classes are included here. Each one will
7-
' be used to create three XmlSerializer objects.
6+
' be used to create three XmlSerializer objects.
87

98
Public Class Instrument
109
Public InstrumentName As String
@@ -19,19 +18,19 @@ Public Class Piece
1918
End Class
2019

2120
Public Class Test
22-
21+
2322
Public Shared Sub Main()
2423
Dim t As New Test()
2524
t.GetSerializers()
26-
End Sub
27-
25+
End Sub
26+
2827
Public Sub GetSerializers()
2928
' Create an array of types.
3029
Dim types(3) As Type
3130
types(0) = GetType(Instrument)
3231
types(1) = GetType(Player)
3332
types(2) = GetType(Piece)
34-
33+
3534
' Create an array for XmlSerializer objects.
3635
Dim serializers(3) As XmlSerializer
3736
serializers = XmlSerializer.FromTypes(types)
@@ -45,4 +44,4 @@ Public Class Test
4544
End Sub
4645
End Class
4746

48-
' </Snippet1>
47+
' </Snippet1>

xml/System.Xml.Serialization/XmlSerializer.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,15 +1897,15 @@ The following example contains two main classes: `PurchaseOrder` and `Test`. The
18971897
<format type="text/markdown"><![CDATA[
18981898
18991899
## Remarks
1900-
The <xref:System.Xml.Serialization.XmlSerializer.FromTypes%2A> method allows you to efficiently create an array of <xref:System.Xml.Serialization.XmlSerializer> objects for processing an array of <xref:System.Type> objects. However, it is recommended for callers to cache the returned serializers when there are repeated calls to this method.
1901-
19021900
1901+
The <xref:System.Xml.Serialization.XmlSerializer.FromTypes%2A> method allows you to efficiently create an array of <xref:System.Xml.Serialization.XmlSerializer> objects for processing an array of <xref:System.Type> objects. However, it's recommended for callers to cache the returned serializers when there are repeated calls to this method.
19031902
19041903
## Examples
1905-
The following example uses the <xref:System.Xml.Serialization.XmlSerializer.FromTypes%2A> method to return an array of <xref:System.Xml.Serialization.XmlSerializer> objects. The code includes three class definitions that are each used to create an array of <xref:System.Type> objects.
19061904
1907-
:::code language="csharp" source="~/snippets/csharp/System.Xml.Serialization/XmlSerializer/FromTypes/source.cs" id="Snippet1":::
1908-
:::code language="vb" source="~/snippets/visualbasic/System.Xml.Serialization/XmlSerializer/FromTypes/source.vb" id="Snippet1":::
1905+
The following example uses the <xref:System.Xml.Serialization.XmlSerializer.FromTypes%2A> method to return an array of <xref:System.Xml.Serialization.XmlSerializer> objects. The code includes three class definitions that are each used to create an array of <xref:System.Type> objects.
1906+
1907+
:::code language="csharp" source="~/snippets/csharp/System.Xml.Serialization/XmlSerializer/FromTypes/source.cs" id="Snippet1":::
1908+
:::code language="vb" source="~/snippets/visualbasic/System.Xml.Serialization/XmlSerializer/FromTypes/source.vb" id="Snippet1":::
19091909
19101910
]]></format>
19111911
</remarks>

0 commit comments

Comments
 (0)