Skip to content

Instantly share code, notes, and snippets.

@tswistak
Last active December 17, 2022 16:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tswistak/10b013803ea4b0a86f185d766b12c090 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
public static void Main(string[] args)
{
// tworzymy listę tablicową
var list = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var evenSquared = from value in list // wyciągamy wartości z listy
where value % 2 == 0 // interesują nas tylko parzyste
select value * value; // zwracamy podniesione do kwadratu
Console.WriteLine(String.Join(", ", evenSquared));
// ta sama operacja ale zapisana funkcjami iterującymi
var evenSquared2 = list
.Where(value => value % 2 == 0)
.Select(value => value * value);
Console.WriteLine(String.Join(", ", evenSquared2));
}
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using Microsoft.CodeAnalysis;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue | DebuggableAttribute.DebuggingModes.DisableOptimizations)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: System.Runtime.CompilerServices.RefSafetyRules(11)]
internal class Program
{
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static Func<int, bool> <>9__0_0;
public static Func<int, int> <>9__0_1;
public static Func<int, bool> <>9__0_2;
public static Func<int, int> <>9__0_3;
internal bool <Main>b__0_0(int value)
{
return value % 2 == 0;
}
internal int <Main>b__0_1(int value)
{
return value * value;
}
internal bool <Main>b__0_2(int value)
{
return value % 2 == 0;
}
internal int <Main>b__0_3(int value)
{
return value * value;
}
}
[System.Runtime.CompilerServices.NullableContext(1)]
public static void Main(string[] args)
{
List<int> list = new List<int>();
list.Add(1);
list.Add(2);
list.Add(3);
list.Add(4);
list.Add(5);
list.Add(6);
list.Add(7);
list.Add(8);
list.Add(9);
list.Add(10);
List<int> source = list;
IEnumerable<int> values = Enumerable.Select(Enumerable.Where(source, <>c.<>9__0_0 ?? (<>c.<>9__0_0 = new Func<int, bool>(<>c.<>9.<Main>b__0_0))), <>c.<>9__0_1 ?? (<>c.<>9__0_1 = new Func<int, int>(<>c.<>9.<Main>b__0_1)));
Console.WriteLine(string.Join(", ", values));
IEnumerable<int> values2 = Enumerable.Select(Enumerable.Where(source, <>c.<>9__0_2 ?? (<>c.<>9__0_2 = new Func<int, bool>(<>c.<>9.<Main>b__0_2))), <>c.<>9__0_3 ?? (<>c.<>9__0_3 = new Func<int, int>(<>c.<>9.<Main>b__0_3)));
Console.WriteLine(string.Join(", ", values2));
}
}
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
byte[] array = new byte[1];
array[0] = P_0;
NullableFlags = array;
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
.assembly _
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = (
01 00 08 00 00 00 00 00
)
.custom instance void [System.Runtime]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = (
01 00 01 00 54 02 16 57 72 61 70 4e 6f 6e 45 78
63 65 70 74 69 6f 6e 54 68 72 6f 77 73 01
)
.custom instance void [System.Runtime]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggableAttribute/DebuggingModes) = (
01 00 07 01 00 00 00 00
)
.permissionset reqmin = (
2e 01 80 8a 53 79 73 74 65 6d 2e 53 65 63 75 72
69 74 79 2e 50 65 72 6d 69 73 73 69 6f 6e 73 2e
53 65 63 75 72 69 74 79 50 65 72 6d 69 73 73 69
6f 6e 41 74 74 72 69 62 75 74 65 2c 20 53 79 73
74 65 6d 2e 52 75 6e 74 69 6d 65 2c 20 56 65 72
73 69 6f 6e 3d 37 2e 30 2e 30 2e 30 2c 20 43 75
6c 74 75 72 65 3d 6e 65 75 74 72 61 6c 2c 20 50
75 62 6c 69 63 4b 65 79 54 6f 6b 65 6e 3d 62 30
33 66 35 66 37 66 31 31 64 35 30 61 33 61 15 01
54 02 10 53 6b 69 70 56 65 72 69 66 69 63 61 74
69 6f 6e 01
)
.hash algorithm 0x00008004 // SHA1
.ver 0:0:0:0
}
.class private auto ansi '<Module>'
{
} // end of class <Module>
.class private auto ansi beforefieldinit Program
extends [System.Runtime]System.Object
{
// Nested Types
.class nested private auto ansi sealed serializable beforefieldinit '<>c'
extends [System.Runtime]System.Object
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
01 00 00 00
)
// Fields
.field public static initonly class Program/'<>c' '<>9'
.field public static class [System.Runtime]System.Func`2<int32, bool> '<>9__0_0'
.field public static class [System.Runtime]System.Func`2<int32, int32> '<>9__0_1'
.field public static class [System.Runtime]System.Func`2<int32, bool> '<>9__0_2'
.field public static class [System.Runtime]System.Func`2<int32, int32> '<>9__0_3'
// Methods
.method private hidebysig specialname rtspecialname static
void .cctor () cil managed
{
// Method begins at RVA 0x21c9
// Code size 11 (0xb)
.maxstack 8
IL_0000: newobj instance void Program/'<>c'::.ctor()
IL_0005: stsfld class Program/'<>c' Program/'<>c'::'<>9'
IL_000a: ret
} // end of method '<>c'::.cctor
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
// Method begins at RVA 0x21c0
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [System.Runtime]System.Object::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method '<>c'::.ctor
.method assembly hidebysig
instance bool '<Main>b__0_0' (
int32 'value'
) cil managed
{
// Method begins at RVA 0x21d5
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.1
IL_0001: ldc.i4.2
IL_0002: rem
IL_0003: ldc.i4.0
IL_0004: ceq
IL_0006: ret
} // end of method '<>c'::'<Main>b__0_0'
.method assembly hidebysig
instance int32 '<Main>b__0_1' (
int32 'value'
) cil managed
{
// Method begins at RVA 0x21dd
// Code size 4 (0x4)
.maxstack 8
IL_0000: ldarg.1
IL_0001: ldarg.1
IL_0002: mul
IL_0003: ret
} // end of method '<>c'::'<Main>b__0_1'
.method assembly hidebysig
instance bool '<Main>b__0_2' (
int32 'value'
) cil managed
{
// Method begins at RVA 0x21d5
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.1
IL_0001: ldc.i4.2
IL_0002: rem
IL_0003: ldc.i4.0
IL_0004: ceq
IL_0006: ret
} // end of method '<>c'::'<Main>b__0_2'
.method assembly hidebysig
instance int32 '<Main>b__0_3' (
int32 'value'
) cil managed
{
// Method begins at RVA 0x21dd
// Code size 4 (0x4)
.maxstack 8
IL_0000: ldarg.1
IL_0001: ldarg.1
IL_0002: mul
IL_0003: ret
} // end of method '<>c'::'<Main>b__0_3'
} // end of class <>c
// Methods
.method public hidebysig static
void Main (
string[] args
) cil managed
{
.custom instance void System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = (
01 00 01 00 00
)
// Method begins at RVA 0x20a4
// Code size 272 (0x110)
.maxstack 3
.locals init (
[0] class [System.Collections]System.Collections.Generic.List`1<int32> list,
[1] class [System.Runtime]System.Collections.Generic.IEnumerable`1<int32> evenSquared,
[2] class [System.Runtime]System.Collections.Generic.IEnumerable`1<int32> evenSquared2
)
IL_0000: nop
IL_0001: newobj instance void class [System.Collections]System.Collections.Generic.List`1<int32>::.ctor()
IL_0006: dup
IL_0007: ldc.i4.1
IL_0008: callvirt instance void class [System.Collections]System.Collections.Generic.List`1<int32>::Add(!0)
IL_000d: nop
IL_000e: dup
IL_000f: ldc.i4.2
IL_0010: callvirt instance void class [System.Collections]System.Collections.Generic.List`1<int32>::Add(!0)
IL_0015: nop
IL_0016: dup
IL_0017: ldc.i4.3
IL_0018: callvirt instance void class [System.Collections]System.Collections.Generic.List`1<int32>::Add(!0)
IL_001d: nop
IL_001e: dup
IL_001f: ldc.i4.4
IL_0020: callvirt instance void class [System.Collections]System.Collections.Generic.List`1<int32>::Add(!0)
IL_0025: nop
IL_0026: dup
IL_0027: ldc.i4.5
IL_0028: callvirt instance void class [System.Collections]System.Collections.Generic.List`1<int32>::Add(!0)
IL_002d: nop
IL_002e: dup
IL_002f: ldc.i4.6
IL_0030: callvirt instance void class [System.Collections]System.Collections.Generic.List`1<int32>::Add(!0)
IL_0035: nop
IL_0036: dup
IL_0037: ldc.i4.7
IL_0038: callvirt instance void class [System.Collections]System.Collections.Generic.List`1<int32>::Add(!0)
IL_003d: nop
IL_003e: dup
IL_003f: ldc.i4.8
IL_0040: callvirt instance void class [System.Collections]System.Collections.Generic.List`1<int32>::Add(!0)
IL_0045: nop
IL_0046: dup
IL_0047: ldc.i4.s 9
IL_0049: callvirt instance void class [System.Collections]System.Collections.Generic.List`1<int32>::Add(!0)
IL_004e: nop
IL_004f: dup
IL_0050: ldc.i4.s 10
IL_0052: callvirt instance void class [System.Collections]System.Collections.Generic.List`1<int32>::Add(!0)
IL_0057: nop
IL_0058: stloc.0
IL_0059: ldloc.0
IL_005a: ldsfld class [System.Runtime]System.Func`2<int32, bool> Program/'<>c'::'<>9__0_0'
IL_005f: dup
IL_0060: brtrue.s IL_0079
IL_0062: pop
IL_0063: ldsfld class Program/'<>c' Program/'<>c'::'<>9'
IL_0068: ldftn instance bool Program/'<>c'::'<Main>b__0_0'(int32)
IL_006e: newobj instance void class [System.Runtime]System.Func`2<int32, bool>::.ctor(object, native int)
IL_0073: dup
IL_0074: stsfld class [System.Runtime]System.Func`2<int32, bool> Program/'<>c'::'<>9__0_0'
IL_0079: call class [System.Runtime]System.Collections.Generic.IEnumerable`1<!!0> [System.Linq]System.Linq.Enumerable::Where<int32>(class [System.Runtime]System.Collections.Generic.IEnumerable`1<!!0>, class [System.Runtime]System.Func`2<!!0, bool>)
IL_007e: ldsfld class [System.Runtime]System.Func`2<int32, int32> Program/'<>c'::'<>9__0_1'
IL_0083: dup
IL_0084: brtrue.s IL_009d
IL_0086: pop
IL_0087: ldsfld class Program/'<>c' Program/'<>c'::'<>9'
IL_008c: ldftn instance int32 Program/'<>c'::'<Main>b__0_1'(int32)
IL_0092: newobj instance void class [System.Runtime]System.Func`2<int32, int32>::.ctor(object, native int)
IL_0097: dup
IL_0098: stsfld class [System.Runtime]System.Func`2<int32, int32> Program/'<>c'::'<>9__0_1'
IL_009d: call class [System.Runtime]System.Collections.Generic.IEnumerable`1<!!1> [System.Linq]System.Linq.Enumerable::Select<int32, int32>(class [System.Runtime]System.Collections.Generic.IEnumerable`1<!!0>, class [System.Runtime]System.Func`2<!!0, !!1>)
IL_00a2: stloc.1
IL_00a3: ldstr ", "
IL_00a8: ldloc.1
IL_00a9: call string [System.Runtime]System.String::Join<int32>(string, class [System.Runtime]System.Collections.Generic.IEnumerable`1<!!0>)
IL_00ae: call void [System.Console]System.Console::WriteLine(string)
IL_00b3: nop
IL_00b4: ldloc.0
IL_00b5: ldsfld class [System.Runtime]System.Func`2<int32, bool> Program/'<>c'::'<>9__0_2'
IL_00ba: dup
IL_00bb: brtrue.s IL_00d4
IL_00bd: pop
IL_00be: ldsfld class Program/'<>c' Program/'<>c'::'<>9'
IL_00c3: ldftn instance bool Program/'<>c'::'<Main>b__0_2'(int32)
IL_00c9: newobj instance void class [System.Runtime]System.Func`2<int32, bool>::.ctor(object, native int)
IL_00ce: dup
IL_00cf: stsfld class [System.Runtime]System.Func`2<int32, bool> Program/'<>c'::'<>9__0_2'
IL_00d4: call class [System.Runtime]System.Collections.Generic.IEnumerable`1<!!0> [System.Linq]System.Linq.Enumerable::Where<int32>(class [System.Runtime]System.Collections.Generic.IEnumerable`1<!!0>, class [System.Runtime]System.Func`2<!!0, bool>)
IL_00d9: ldsfld class [System.Runtime]System.Func`2<int32, int32> Program/'<>c'::'<>9__0_3'
IL_00de: dup
IL_00df: brtrue.s IL_00f8
IL_00e1: pop
IL_00e2: ldsfld class Program/'<>c' Program/'<>c'::'<>9'
IL_00e7: ldftn instance int32 Program/'<>c'::'<Main>b__0_3'(int32)
IL_00ed: newobj instance void class [System.Runtime]System.Func`2<int32, int32>::.ctor(object, native int)
IL_00f2: dup
IL_00f3: stsfld class [System.Runtime]System.Func`2<int32, int32> Program/'<>c'::'<>9__0_3'
IL_00f8: call class [System.Runtime]System.Collections.Generic.IEnumerable`1<!!1> [System.Linq]System.Linq.Enumerable::Select<int32, int32>(class [System.Runtime]System.Collections.Generic.IEnumerable`1<!!0>, class [System.Runtime]System.Func`2<!!0, !!1>)
IL_00fd: stloc.2
IL_00fe: ldstr ", "
IL_0103: ldloc.2
IL_0104: call string [System.Runtime]System.String::Join<int32>(string, class [System.Runtime]System.Collections.Generic.IEnumerable`1<!!0>)
IL_0109: call void [System.Console]System.Console::WriteLine(string)
IL_010e: nop
IL_010f: ret
} // end of method Program::Main
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
// Method begins at RVA 0x21c0
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [System.Runtime]System.Object::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method Program::.ctor
} // end of class Program
.class private auto ansi sealed beforefieldinit Microsoft.CodeAnalysis.EmbeddedAttribute
extends [System.Runtime]System.Attribute
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
01 00 00 00
)
.custom instance void Microsoft.CodeAnalysis.EmbeddedAttribute::.ctor() = (
01 00 00 00
)
// Methods
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
// Method begins at RVA 0x2050
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [System.Runtime]System.Attribute::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method EmbeddedAttribute::.ctor
} // end of class Microsoft.CodeAnalysis.EmbeddedAttribute
.class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.NullableAttribute
extends [System.Runtime]System.Attribute
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
01 00 00 00
)
.custom instance void Microsoft.CodeAnalysis.EmbeddedAttribute::.ctor() = (
01 00 00 00
)
.custom instance void [System.Runtime]System.AttributeUsageAttribute::.ctor(valuetype [System.Runtime]System.AttributeTargets) = (
01 00 84 6b 00 00 02 00 54 02 0d 41 6c 6c 6f 77
4d 75 6c 74 69 70 6c 65 00 54 02 09 49 6e 68 65
72 69 74 65 64 00
)
// Fields
.field public initonly uint8[] NullableFlags
// Methods
.method public hidebysig specialname rtspecialname
instance void .ctor (
uint8 ''
) cil managed
{
// Method begins at RVA 0x2059
// Code size 24 (0x18)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [System.Runtime]System.Attribute::.ctor()
IL_0006: nop
IL_0007: ldarg.0
IL_0008: ldc.i4.1
IL_0009: newarr [System.Runtime]System.Byte
IL_000e: dup
IL_000f: ldc.i4.0
IL_0010: ldarg.1
IL_0011: stelem.i1
IL_0012: stfld uint8[] System.Runtime.CompilerServices.NullableAttribute::NullableFlags
IL_0017: ret
} // end of method NullableAttribute::.ctor
.method public hidebysig specialname rtspecialname
instance void .ctor (
uint8[] ''
) cil managed
{
// Method begins at RVA 0x2072
// Code size 15 (0xf)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [System.Runtime]System.Attribute::.ctor()
IL_0006: nop
IL_0007: ldarg.0
IL_0008: ldarg.1
IL_0009: stfld uint8[] System.Runtime.CompilerServices.NullableAttribute::NullableFlags
IL_000e: ret
} // end of method NullableAttribute::.ctor
} // end of class System.Runtime.CompilerServices.NullableAttribute
.class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.NullableContextAttribute
extends [System.Runtime]System.Attribute
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
01 00 00 00
)
.custom instance void Microsoft.CodeAnalysis.EmbeddedAttribute::.ctor() = (
01 00 00 00
)
.custom instance void [System.Runtime]System.AttributeUsageAttribute::.ctor(valuetype [System.Runtime]System.AttributeTargets) = (
01 00 4c 14 00 00 02 00 54 02 0d 41 6c 6c 6f 77
4d 75 6c 74 69 70 6c 65 00 54 02 09 49 6e 68 65
72 69 74 65 64 00
)
// Fields
.field public initonly uint8 Flag
// Methods
.method public hidebysig specialname rtspecialname
instance void .ctor (
uint8 ''
) cil managed
{
// Method begins at RVA 0x2082
// Code size 15 (0xf)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [System.Runtime]System.Attribute::.ctor()
IL_0006: nop
IL_0007: ldarg.0
IL_0008: ldarg.1
IL_0009: stfld uint8 System.Runtime.CompilerServices.NullableContextAttribute::Flag
IL_000e: ret
} // end of method NullableContextAttribute::.ctor
} // end of class System.Runtime.CompilerServices.NullableContextAttribute
.class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.RefSafetyRulesAttribute
extends [System.Runtime]System.Attribute
{
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (
01 00 00 00
)
.custom instance void Microsoft.CodeAnalysis.EmbeddedAttribute::.ctor() = (
01 00 00 00
)
.custom instance void [System.Runtime]System.AttributeUsageAttribute::.ctor(valuetype [System.Runtime]System.AttributeTargets) = (
01 00 02 00 00 00 02 00 54 02 0d 41 6c 6c 6f 77
4d 75 6c 74 69 70 6c 65 00 54 02 09 49 6e 68 65
72 69 74 65 64 00
)
// Fields
.field public initonly int32 Version
// Methods
.method public hidebysig specialname rtspecialname
instance void .ctor (
int32 ''
) cil managed
{
// Method begins at RVA 0x2092
// Code size 15 (0xf)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [System.Runtime]System.Attribute::.ctor()
IL_0006: nop
IL_0007: ldarg.0
IL_0008: ldarg.1
IL_0009: stfld int32 System.Runtime.CompilerServices.RefSafetyRulesAttribute::Version
IL_000e: ret
} // end of method RefSafetyRulesAttribute::.ctor
} // end of class System.Runtime.CompilerServices.RefSafetyRulesAttribute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment