Skip to content

Commit 1bf8359

Browse files
committed
Fix warnings
1 parent c07237b commit 1bf8359

File tree

2 files changed

+2
-50
lines changed

2 files changed

+2
-50
lines changed

TryCSharp.Samples/Basic/BitConverterSamples01.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void Execute()
3636
bytes = new byte[] {1, 0, 0, 0};
3737
Output.WriteLine(BitConverter.ToInt32(bytes, 0));
3838

39-
bytes = BitConverter.GetBytes((byte) 'a');
39+
bytes = BitConverter.GetBytes((short) 'a');
4040
Output.WriteLine(BitConverter.ToChar(bytes, 0));
4141
}
4242
}

TryCSharp.Samples/Threading/ThreadLocalSamples01.cs

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void Execute()
2222
// ・フィールドの値は常に、その型のデフォルト値で初期化される。初期値を設定しても無視される。
2323
//
2424
// ThreadLocal<T>は、上記の点を解決している。つまり
25-
// ・インスタンスフィールドに対応している。
25+
// ・インスタンスフィールドに対応している。(が、警告が出る)
2626
// ・フィールドの値を初期値で初期化出来る。
2727
//
2828
// 利用方法は、System.Lazyと似ており、コンストラクタに初期化のためのデリゲートを渡す。
@@ -66,46 +66,7 @@ public void Execute()
6666
countdown.Wait();
6767
}
6868

69-
//
70-
// インスタンスフィールドのThreadStatic属性の確認
71-
// ThreadStatic属性は、インスタンスフィールドに対しては効果が無い。
72-
// なので、出力される値は2,3,4,5,6...とインクリメントされていく.
73-
//
74-
using (var countdown = new CountdownEvent(numberOfParallels))
75-
{
76-
for (var i = 0; i < numberOfParallels; i++)
77-
{
78-
new Thread(() =>
79-
{
80-
Output.WriteLine("ThreadStatic [count3]>>> {0}", count3++);
81-
countdown.Signal();
82-
}).Start();
83-
}
84-
85-
countdown.Wait();
86-
}
87-
88-
//
89-
// インスタンスフィールドのThreadLocal<T>の確認
90-
// ThreadLocal<T>は、インスタンスフィールドに対しても問題なく利用できる。
91-
// なので、出力される値は4となる。
92-
//
93-
using (var countdown = new CountdownEvent(numberOfParallels))
94-
{
95-
for (var i = 0; i < numberOfParallels; i++)
96-
{
97-
new Thread(() =>
98-
{
99-
Output.WriteLine("ThreadLocal<T> [count4]>>> {0}", count4.Value++);
100-
countdown.Signal();
101-
}).Start();
102-
}
103-
104-
countdown.Wait();
105-
}
106-
10769
count2.Dispose();
108-
count4.Dispose();
10970
}
11071

11172
#region Static Fields
@@ -116,14 +77,5 @@ public void Execute()
11677
private static readonly ThreadLocal<int> count2 = new ThreadLocal<int>(() => 2);
11778

11879
#endregion
119-
120-
#region Fields
121-
122-
// ReSharper disable once ThreadStaticAtInstanceField
123-
[ThreadStatic] private int count3 = 2;
124-
125-
private readonly ThreadLocal<int> count4 = new ThreadLocal<int>(() => 4);
126-
127-
#endregion
12880
}
12981
}

0 commit comments

Comments
 (0)