回答編集履歴

2

見直しキャンペーン中

2023/07/30 07:22

投稿

TN8001
TN8001

スコア9341

test CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
  本質的には理解されていると思うのですが、`new`すればしただけインスタンスが増えていきます。
15
15
 
16
- ```C#
16
+ ```cs
17
17
  private void Button_Click_3(object sender, RoutedEventArgs e)
18
18
  {
19
19
  WordList wl = new WordList();
@@ -24,7 +24,7 @@
24
24
  当然`dataList`も同じ数だけ作られることになり、それぞれは全く無関係に編集・追加できてしまいます。
25
25
 
26
26
  手抜きな解決策は`static`にすることですが、
27
- ```C#
27
+ ```cs
28
28
  public static ObservableCollection<Product> DataList { get; } = new ObservableCollection<Product>();
29
29
  ```
30
30
  それは無しということになると、何らかの手で`new`を1回だけにする必要があります。
@@ -44,7 +44,7 @@
44
44
 
45
45
  .NET6です^^
46
46
  MainWindow
47
- ```xaml
47
+ ```xml
48
48
  <Window
49
49
  x:Class="Q6fg0h19dpimexx.MainWindow"
50
50
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
@@ -76,7 +76,7 @@
76
76
  </Grid>
77
77
  </Window>
78
78
  ```
79
- ```C#
79
+ ```cs
80
80
  using System.Collections.ObjectModel;
81
81
  using System.IO;
82
82
  using System.Linq;
@@ -160,7 +160,7 @@
160
160
  ```
161
161
 
162
162
  WordListWindow1
163
- ```xaml
163
+ ```xml
164
164
  <Window
165
165
  x:Class="Q6fg0h19dpimexx.WordListWindow1"
166
166
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
@@ -177,7 +177,7 @@
177
177
  </DockPanel>
178
178
  </Window>
179
179
  ```
180
- ```C#
180
+ ```cs
181
181
  using System.Windows;
182
182
 
183
183
  namespace Q6fg0h19dpimexx
@@ -202,7 +202,7 @@
202
202
  ```
203
203
 
204
204
  WordListWindow2
205
- ```xaml
205
+ ```xml
206
206
  <Window
207
207
  x:Class="Q6fg0h19dpimexx.WordListWindow2"
208
208
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
@@ -219,7 +219,7 @@
219
219
  </DockPanel>
220
220
  </Window>
221
221
  ```
222
- ```C#
222
+ ```cs
223
223
  using System.ComponentModel;
224
224
  using System.Windows;
225
225
 

1

言い回し

2022/04/25 12:23

投稿

TN8001
TN8001

スコア9341

test CHANGED
@@ -27,7 +27,7 @@
27
27
  ```C#
28
28
  public static ObservableCollection<Product> DataList { get; } = new ObservableCollection<Product>();
29
29
  ```
30
- それは無しということになると、`new`を1回だけにしなくてはなりません
30
+ それは無しということになると、何らかの手で`new`を1回だけにする必要がありま
31
31
  * `MainWindow`で初めに1回だけ`dataList`を作り、`WordList`(`FileIO`)に渡す
32
32
  `MainWindow`は普通1個しか作らないので、データ置き場にはちょうどいいです。
33
33
  * `WordList`を都度`new`しない