Skip to content

Commit a4f66d0

Browse files
committed
C# 语法 ref / out 出错测试.
1 parent f0a6396 commit a4f66d0

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

UnitTestDll/UnitTestDll.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<Compile Include="Test_ByLynn.cs" />
6565
<Compile Include="Test_ByDuskforest.cs" />
6666
<Compile Include="test_enum.cs" />
67+
<Compile Include="test_RefOut.cs" />
6768
<Compile Include="test_string_switch.cs" />
6869
<Compile Include="没有实现的IL.cs" />
6970
</ItemGroup>

UnitTestDll/test_RefOut.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using UnitTest;
3+
using System.Collections.Generic;
4+
5+
namespace UnitTestDll
6+
{
7+
public class test_RefOut
8+
{
9+
private class UserDefClass {
10+
public int value01;
11+
public string value02 = "";
12+
13+
public void StringToValue(ref string v, string str) {
14+
v = str;
15+
}
16+
}
17+
18+
19+
public static void UnitTest_Out() {
20+
Dictionary<int, UserDefClass> dict = new Dictionary<int,UserDefClass>();
21+
UserDefClass obj = new UserDefClass();
22+
obj.value01 = 888;
23+
dict.Add(0, obj);
24+
UserDefClass testObj;
25+
if(dict.ContainsKey(0)) {
26+
testObj = dict[0];
27+
Logger.Log(string.Format("Value01 : {0}", testObj.value01));
28+
}
29+
if(dict.TryGetValue(0, out testObj)) {
30+
Logger.Log("Test OK.");
31+
}
32+
}
33+
34+
public static void UnitTest_Ref() {
35+
36+
UserDefClass obj = new UserDefClass();
37+
obj.StringToValue(ref obj.value02, "test");
38+
Logger.Log(obj.value02);
39+
40+
}
41+
42+
}
43+
}

0 commit comments

Comments
 (0)