static void Main(string[] args)
{
Show();//异步
var msg = TestOutRef();
Console.WriteLine(msg);
}
public static async void Show()
{
await Task.Run(() =>
{
for (int i = 0; i < 100; i++)
{
Console.WriteLine(i);
}
});
}
public static async Task<string> TestOutRef()
{
string text = string.Empty;
int[] listInt = new int[5];
string[] Strlist = { "张三", "李四", "王五", "赵六", "周七" };
Dictionary<object, int> keyValues = new Dictionary<object, int>();
await Task.Run(() =>
{
for (int i = 0; i < 5; i++)
{
listInt[i] = i;
keyValues.Add(Strlist[i], i);
}
});
string msg = "";//ref需赋初始值
TestRef(listInt, keyValues, ref msg);//需与ref关键字一起传递
return msg;
}
public static string TestRef(int[] ListInt, Dictionary<object, int> keyValues, ref string msg)//使用ref传递,参数列表对应参数需加ref关键字
{
msg = "Test Out!!";
Dictionary<object, object> keys = new Dictionary<object, object>();
for (int i = 0; i < ListInt.Length; i++)
{
foreach (var item in keyValues)
{
msg += item.Key + "," + item.Value;
keys.Add(item.Key, item.Value);
}
}
string OutMsg;//不需要赋初始值
TestOut(keys, out OutMsg);
return OutMsg;
}
public static string TestOut(Dictionary<object, object> keys, out string OutMsg)
{
OutMsg = "";
foreach (var item in keys)
{
OutMsg += item.Key + "," + item.Value;
}
return OutMsg;
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交