本文整理汇总了C#中System.Collections.Immutable.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Immutable.FirstOrDefault方法的具体用法?C# System.Collections.Immutable.FirstOrDefault怎么用?C# System.Collections.Immutable.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Immutable
的用法示例。
在下文中一共展示了System.Collections.Immutable.FirstOrDefault方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrivateImplementationDetails
public void PrivateImplementationDetails()
{
var source =
@"class C
{
static int[] F = new int[] { 1, 2, 3 };
int[] G = new int[] { 4, 5, 6 };
int M(int index)
{
return F[index] + G[index];
}
}";
var compilation0 = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
var compilation1 = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
var testData0 = new CompilationTestData();
var bytes0 = compilation0.EmitToArray(testData: testData0);
using (var md0 = ModuleMetadata.CreateFromImage(bytes0))
{
var reader0 = md0.MetadataReader;
var typeNames = new[] { reader0 }.GetStrings(reader0.GetTypeDefNames());
Assert.NotNull(typeNames.FirstOrDefault(n => n.StartsWith("<PrivateImplementationDetails>")));
}
var methodData0 = testData0.GetMethodData("C.M");
var method0 = compilation0.GetMember<MethodSymbol>("C.M");
var generation0 = EmitBaseline.CreateInitialBaseline(ModuleMetadata.CreateFromImage(bytes0), m => GetLocalNames(methodData0));
var method1 = compilation1.GetMember<MethodSymbol>("C.M");
var diff1 = compilation1.EmitDifference(
generation0,
ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, method0, method1, GetEquivalentNodesMap(method1, method0), preserveLocalVariables: true)));
diff1.VerifyIL("C.M", @"
{
// Code size 22 (0x16)
.maxstack 3
.locals init ([int] V_0,
int V_1)
IL_0000: nop
IL_0001: ldsfld ""int[] C.F""
IL_0006: ldarg.1
IL_0007: ldelem.i4
IL_0008: ldarg.0
IL_0009: ldfld ""int[] C.G""
IL_000e: ldarg.1
IL_000f: ldelem.i4
IL_0010: add
IL_0011: stloc.1
IL_0012: br.s IL_0014
IL_0014: ldloc.1
IL_0015: ret
}");
}