├── Chapter09
├── packages.config
├── App.config
├── Program.cs
├── NameofWithAlias.cs
├── HorribleCode.cs
├── GlobalSuppressions.cs
├── Chapter09.csproj
├── FormatPriceInterpolatedVerbatim.cs
├── EagerEvaluation.cs
├── FormatPrice.cs
├── FormatPriceInterpolated.cs
├── SimpleNameof.cs
├── QualifiedNameof.cs
├── BirthdayInAllCultures.cs
├── FormatDateInvariant.cs
├── SqlInjection.cs
└── LazyEvaluation.cs
├── Chapter10
├── packages.config
├── App.config
├── Program.cs
├── Person.cs
├── CombineEnums.cs
├── UsingStaticExtensionMethods2.cs
├── Chapter10.csproj
├── Point.cs
├── CoordinatesOldStyle.cs
├── CoordinatesUsingStatic.cs
├── UsingStaticExtensionMethods1.cs
├── DictionaryInitialization.cs
├── ObjectInitializerIndexer.cs
├── LoggingFilter.cs
├── SpecializedAddExtensionMethod.cs
├── CollectionInitializerExtensionMethods.cs
├── FirstExceptionFilter.cs
├── AddRangeAsAdd.cs
├── SwitchOnEnum.cs
├── ConcurrentDictionaryCollectionInitializer.cs
└── SimpleRetry.cs
├── CSharp8
├── Chapter15
│ ├── Program.cs
│ ├── Chapter15.csproj
│ ├── DamnItOperator.cs
│ ├── BrokenInitialExample.cs
│ ├── GeoServiceDemo.cs
│ ├── IGeoService.cs
│ ├── NullableAddressFix1.cs
│ ├── EverythingNonNullable.cs
│ ├── GeoClient.cs
│ ├── NullableAddressFix3.cs
│ ├── NullableAddressFix2.cs
│ ├── AsyncDisposal.cs
│ ├── NullableAddress.cs
│ ├── DeconstructionPattern.cs
│ ├── PropertyPatterns1.cs
│ ├── SwitchExpressionBodiedMember.cs
│ ├── SwitchExpression.cs
│ └── DamnItOperatorValidation.cs
└── README.md
├── Chapter11
├── App.config
├── packages.config
├── Program.cs
├── Chapter11.csproj
├── InferredTupleElementNames.cs
├── ElementAccess.cs
├── Indexing.cs
├── FibonacciWithTuples.cs
├── EqualityOperators.cs
├── RegularComparisons.cs
├── FibonacciWithoutTuples.cs
├── Game.cs
├── StructuralComparisons.cs
├── FibonacciWithGenerator.cs
├── HighScoreDisplayWithTuples.cs
├── HighScoreDisplayWithoutTuples.cs
├── MinMax3.cs
├── MinMax1.cs
└── MinMax2.cs
├── Chapter04Com
├── App.config
├── Program.cs
├── SaveFileNew.cs
├── ExcelDynamic.cs
├── NamedIndexers.cs
└── SaveFileOld.cs
├── Chapter09Net40
├── App.config
├── Chapter09Net40.csproj
├── Program.cs
├── FormattableStringFactory.cs
└── FormattableString.cs
├── Chapter02
├── Program.cs
├── Chapter02.csproj
├── IteratorBlockWithFinallyDemo1.cs
├── TypeOfExample.cs
├── IteratorBlockWithFinallyDemo3.cs
├── FixedBuffers.cs
├── FixedBuffersInFields.cs
├── NullableBoxing.cs
├── NullableGetType.cs
├── PartialDemo1.cs
├── SimpleIterator.cs
├── TypeConstraints.cs
├── IteratorBlockWithFinally.cs
├── StaticClasses.cs
├── NamesWithArray.cs
├── IteratorBlockWithFinallyDemo2.cs
├── NamesWithArrayList.cs
├── FibonacciSequence.cs
├── GenericMethod.cs
├── NamesWithList.cs
├── LineReader.cs
├── NamesWithStringCollection.cs
├── ExpandedForEach.cs
├── GenericCounter.cs
├── DecompilationExampleOriginal.cs
└── PartialDemo2.cs
├── Chapter05
├── Program.cs
├── AsyncEntryPoint.cs
├── Chapter05.csproj
├── ManuallyInducedCancellation.cs
├── AsyncLambda.cs
├── AwaitCompletedTask.cs
├── PrintPageLength.cs
├── LazyArgumentValidation.cs
├── UnsafeCodeInAsyncMethod.cs
├── EagerArgumentValidation1.cs
├── AwaitingFailedOperations.cs
├── AsyncIntro.cs
├── EagerArgumentValidation2.cs
└── EagerArgumentValidation3.cs
├── Chapter06
├── Program.cs
├── Chapter06.csproj
├── SimpleAsyncMethod.cs
├── AwaitInsideLoop.cs
├── AsyncMethodWithSimpleLoop.cs
└── AwaitInsideTryFinally.cs
├── Chapter12
├── Program.cs
├── TupleLiteralDeconstruction.cs
├── Chapter12.csproj
├── TupleDeconstructionExplicitTyping.cs
├── TupleDeconstructionEvaluationOrdering.cs
├── DateTimeDeconstruction.cs
├── TupleDeconstructionOverview.cs
├── TupleDeconstructionAssignments.cs
├── Point.cs
├── TupleDeconstructionEvaluationOrderingExplained.cs
├── ConstantPatterns.cs
├── TypePatternWithNullableType.cs
├── FizzBuzz.cs
├── FibonacciSwitch.cs
├── DateTimeDeconstruction2.cs
├── NumericBounds.cs
├── ShapePerimeterWithPatternsIfElse.cs
├── GenericTypeCase.cs
├── Shape.cs
├── ShapePerimeterWithPatternsSwitchCase.cs
└── ShapePerimeterBeforePatterns.cs
├── Chapter13
├── Program.cs
├── StackAllocWithInitializer.cs
├── Vector3D.cs
├── RefReassignment.cs
├── RefLocalIntro.cs
├── RefReturnNoLocal.cs
├── NoParameterCopy.cs
├── Vector3DExtensions.cs
├── RefLocalIdentityConversions.cs
├── Chapter13.csproj
├── RefReturnSimpleNoLocal.cs
├── RefReadonly.cs
├── RefReturnSimple.cs
├── InParameterOverloading.cs
├── RefParameterRecap.cs
├── ImplicitFieldCopy.cs
├── UsingVector3DExtensions.cs
├── RefLocalField.cs
├── LargeStruct.cs
├── RefReturnIndexer.cs
├── FixedSpan.cs
├── ImplicitParameterCopy.cs
├── RefLocalArrays.cs
├── InParameterOptions.cs
├── ReadOnlyArrayView.cs
├── YearMonthDay.cs
├── GenerateRandomString1.cs
├── GenerateRandomString3.cs
├── RefConditional.cs
├── GenerateRandomString2.cs
├── ReadonlyStructUnsafeViolation.cs
├── InParameterSideEffects.cs
├── GenerateRandomString4.cs
└── SafeInParameters.cs
├── Chapter14
├── Program.cs
├── Preconditions.cs
├── FieldAttributes.cs
├── NonTrailingNamedArguments.cs
├── DefaultExpression1.cs
├── LocalMethodInLoop.cs
├── DefaultLiteralOptionalParameter.cs
├── LocalMethodVariableCapture1.cs
├── Chapter14.csproj
├── DefaultExpression2.cs
├── ExplicitListDefaultValue.cs
├── LocalMethodIntro.cs
├── LocalMethodVariableCapture3.cs
├── LocalMethodVariableCapture2.cs
├── LocalMethodVariableCapture1Equivalent.cs
├── LocalMethodVariableCapture3Equivalent.cs
├── GenericConstraints.cs
├── SelectBeforeLocalMethods.cs
├── SelectWithLocalMethods.cs
├── LocalMethodVariableCapture2Equivalent.cs
├── LocalMethodUsingThisInStruct.cs
├── OutVarInConstructorInitializer.cs
└── OverloadResolution.cs
├── Chapter03
├── Program.cs
├── ExtensionMethodInvocation.cs
├── ExpressionTreeIntro.cs
├── Chapter03.csproj
├── ExpressionTreeCompilation.cs
├── AnonymousTypeIntro.cs
├── NestedObjectInitializer.cs
├── ExtensionMethodChaining.cs
├── QueryWithLocalVariables.cs
├── QueryExpression1.cs
├── NestedMethodCalls.cs
├── ExpressionTreeIntroImpl.cs
├── QueryExpression2Impl.cs
├── QueryExpression2.cs
├── CapturingMultipleInstantiations.cs
├── CapturingMultipleInstantiationsImpl.cs
├── CapturingMultipleScopes.cs
└── CapturedVariablesDemo.cs
├── Chapter04
├── Program.cs
├── Chapter04.csproj
├── DynamicAddition.cs
├── DynamicTypingIntro.cs
├── LinqCovariance.cs
├── LinqWithoutVariance.cs
├── DynamicAnonymousTypes.cs
├── InvalidCalls.cs
├── OptionalParameterIntro.cs
├── DynamicTypingAndExplicitInterfaceImplementation.cs
├── InvalidLinqQuery.cs
├── DynamicLinqQuery.cs
├── DynamicJsonParsing.cs
├── DynamicLinqQueryWithQueryable.cs
├── ExpandoObjectIntroduction.cs
├── DyanamicOverloadResolution.cs
├── SimpleDynamicExample.cs
└── MixedDynamicAndStaticOverloadResolution.cs
├── Chapter07
├── Program.cs
├── Chapter07.csproj
├── CallerInfoDemo.cs
├── ForEachCapture.cs
├── ForLoopCapture.cs
├── DynamicAndCallerInfo.cs
├── CallerInfoConstructors.cs
├── OldPropertyNotifier.cs
└── NewPropertyNotifier.cs
└── Chapter08
├── Person.cs
├── Chapter08.csproj
├── Vector.cs
├── PointStruct.cs
├── ReadOnlyListView.cs
└── Point.cs
/Chapter09/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Chapter10/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/CSharp8/Chapter15/Program.cs:
--------------------------------------------------------------------------------
1 | using JonSkeet.DemoUtil;
2 |
3 | namespace Chapter15
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args) => ApplicationChooser.Run();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Chapter09/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter10/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter11/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Chapter04Com/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Chapter09Net40/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Chapter02/Program.cs:
--------------------------------------------------------------------------------
1 | using JonSkeet.DemoUtil;
2 |
3 | namespace Chapter02
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | ApplicationChooser.Run();
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/Chapter05/Program.cs:
--------------------------------------------------------------------------------
1 | using JonSkeet.DemoUtil;
2 |
3 | namespace Chapter05
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | ApplicationChooser.Run();
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/Chapter06/Program.cs:
--------------------------------------------------------------------------------
1 | using JonSkeet.DemoUtil;
2 |
3 | namespace Chapter06
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | ApplicationChooser.Run();
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/Chapter12/Program.cs:
--------------------------------------------------------------------------------
1 | using JonSkeet.DemoUtil;
2 |
3 | namespace Chapter12
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | ApplicationChooser.Run();
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/Chapter13/Program.cs:
--------------------------------------------------------------------------------
1 | using JonSkeet.DemoUtil;
2 |
3 | namespace Chapter13
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | ApplicationChooser.Run();
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/Chapter14/Program.cs:
--------------------------------------------------------------------------------
1 | using JonSkeet.DemoUtil;
2 |
3 | namespace Chapter14
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | ApplicationChooser.Run();
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/Chapter11/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Chapter03/Program.cs:
--------------------------------------------------------------------------------
1 | using JonSkeet.DemoUtil;
2 |
3 | namespace Chapter03
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | ApplicationChooser.Run();
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter04/Program.cs:
--------------------------------------------------------------------------------
1 | using JonSkeet.DemoUtil;
2 |
3 | namespace Chapter04
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | ApplicationChooser.Run();
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter10/Program.cs:
--------------------------------------------------------------------------------
1 | using JonSkeet.DemoUtil;
2 |
3 | namespace Chapter10
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | ApplicationChooser.Run();
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter04Com/Program.cs:
--------------------------------------------------------------------------------
1 | using JonSkeet.DemoUtil;
2 |
3 | namespace Chapter04Com
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | ApplicationChooser.Run();
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter09/Program.cs:
--------------------------------------------------------------------------------
1 | using JonSkeet.DemoUtil;
2 |
3 | namespace Chapter09
4 | {
5 | public class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | ApplicationChooser.Run();
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter11/Program.cs:
--------------------------------------------------------------------------------
1 | using JonSkeet.DemoUtil;
2 |
3 | namespace Chapter11
4 | {
5 | public class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | ApplicationChooser.Run();
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter07/Program.cs:
--------------------------------------------------------------------------------
1 | using JonSkeet.DemoUtil;
2 | using System;
3 |
4 | namespace Chapter07
5 | {
6 | class Program
7 | {
8 | static void Main(string[] args)
9 | {
10 | ApplicationChooser.Run();
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Chapter08/Person.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.ComponentModel;
3 |
4 | namespace Chapter08
5 | {
6 | [Description("Listing 8.10")]
7 | public class Person
8 | {
9 | public List Friends { get; } = new List();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Chapter08/Chapter08.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netstandard2.0
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Chapter14/Preconditions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Chapter14
4 | {
5 | static class Preconditions
6 | {
7 | internal static T CheckNotNull(T value, string paramName) where T : class
8 | => value ?? throw new ArgumentNullException(paramName);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Chapter09Net40/Chapter09Net40.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net40
6 | Chapter09Net40.Program
7 |
8 |
--------------------------------------------------------------------------------
/Chapter08/Vector.cs:
--------------------------------------------------------------------------------
1 | namespace Chapter08
2 | {
3 | public sealed class Vector
4 | {
5 | public double X { get; }
6 | public double Y { get; }
7 |
8 | public Vector(double x, double y)
9 | {
10 | X = x;
11 | Y = y;
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter10/Person.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace Chapter10
6 | {
7 | class Person
8 | {
9 | public string Name { get; set; }
10 | public string Town { get; set; }
11 | public List Contacts { get; } = new List();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Chapter13/StackAllocWithInitializer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Chapter13
4 | {
5 | class StackAllocWithInitializer
6 | {
7 | unsafe static void Main()
8 | {
9 | Span span = stackalloc int[] { 1, 2, 3 };
10 | int* pointer = stackalloc int[] { 4, 5, 6 };
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Chapter09/NameofWithAlias.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 | using GuidAlias = System.Guid;
4 |
5 | namespace Chapter09
6 | {
7 | [Description("Listing 9.17")]
8 | class NameofWithAlias
9 | {
10 | static void Main()
11 | {
12 | Console.WriteLine(nameof(GuidAlias));
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Chapter10/CombineEnums.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 |
3 | using static System.Reflection.BindingFlags;
4 |
5 | namespace Chapter10
6 | {
7 | class CombineEnums
8 | {
9 | static void Main()
10 | {
11 | var fields = typeof(CombineEnums).GetFields(Instance | Static | Public | NonPublic);
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter07/Chapter07.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | netcoreapp2.0
5 | Chapter07.Program
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Chapter13/Vector3D.cs:
--------------------------------------------------------------------------------
1 | namespace Chapter13
2 | {
3 | public readonly struct Vector3D
4 | {
5 | public double X { get; }
6 | public double Y { get; }
7 | public double Z { get; }
8 |
9 | public Vector3D(double x, double y, double z)
10 | {
11 | X = x;
12 | Y = y;
13 | Z = z;
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Chapter08/PointStruct.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 |
3 | namespace Chapter08
4 | {
5 | [Description("Listing 8.12")]
6 | public struct PointStruct
7 | {
8 | public double X { get; }
9 | public double Y { get; }
10 |
11 | public PointStruct(double x, double y)
12 | {
13 | X = x;
14 | Y = y;
15 | }
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter03/ExtensionMethodInvocation.cs:
--------------------------------------------------------------------------------
1 | using NodaTime.Extensions;
2 | using System;
3 | using System.ComponentModel;
4 |
5 | namespace CSharpInDepth.Chapter03
6 | {
7 | [Description("Listing 3.16")]
8 | class ExtensionMethodInvocation
9 | {
10 | static void Main()
11 | {
12 | var currentInstant = DateTimeOffset.UtcNow.ToInstant();
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Chapter13/RefReassignment.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Chapter13
4 | {
5 | class RefReassignment
6 | {
7 | static void Main()
8 | {
9 | int x = 10;
10 | int y = 20;
11 | ref int r = ref x;
12 | r++;
13 | r = ref y;
14 | r++;
15 | Console.WriteLine($"x={x}; y={y}");
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter14/FieldAttributes.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Chapter14
4 | {
5 | [AttributeUsage(AttributeTargets.Field)]
6 | class DemoAttribute : Attribute
7 | {
8 | }
9 |
10 | class FieldAttributes
11 | {
12 | [field: Demo]
13 | public static int Value { get; set; }
14 |
15 | [field: Demo]
16 | public static event EventHandler Foo;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter13/RefLocalIntro.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 |
4 | namespace Chapter13
5 | {
6 | [Description("Listing 13.2")]
7 | public class RefLocalIntro
8 | {
9 | static void Main()
10 | {
11 | int x = 10;
12 | ref int y = ref x;
13 | x++;
14 | y++;
15 | Console.WriteLine(x);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter09/HorribleCode.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Chapter09
4 | {
5 | class HorribleCode
6 | {
7 | static void Main(string[] args)
8 | {
9 | Console.WriteLine($@"Hello {((Func)(() =>
10 | {
11 | Console.Write("What's your name? ");
12 | return Console.ReadLine();
13 | }))()}!");
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Chapter09Net40/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Chapter09Net40
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | int value = 5;
10 | FormattableString formattable = $"value={value}";
11 | Console.WriteLine(formattable.Format);
12 | Console.WriteLine(formattable.GetArgument(0));
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Chapter14/NonTrailingNamedArguments.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Chapter14
4 | {
5 | class NonTrailingNamedArguments
6 | {
7 | static void Method(int x, int y = 5, int z = 10)
8 | {
9 | Console.WriteLine("x={0}; y={1}; z={2}", x, y, z);
10 | }
11 |
12 | static void Main()
13 | {
14 | Method(x: 1, y: 2, 3);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Chapter09/GlobalSuppressions.cs:
--------------------------------------------------------------------------------
1 |
2 | // This file is used by Code Analysis to maintain SuppressMessage
3 | // attributes that are applied to this project.
4 | // Project-level suppressions either have no target or are given
5 | // a specific target and scoped to a namespace, type, member, etc.
6 |
7 | using System.Diagnostics.CodeAnalysis;
8 |
9 | [assembly: SuppressMessage("Style", "IDE0030", Justification = "Introduced in chapter 8")]
--------------------------------------------------------------------------------
/Chapter14/DefaultExpression1.cs:
--------------------------------------------------------------------------------
1 | using System.Threading;
2 | using System.Threading.Tasks;
3 |
4 | namespace Chapter14
5 | {
6 | class DefaultExpression1
7 | {
8 | public async Task FetchValueAsync(string key, CancellationToken cancellationToken = default)
9 | {
10 | await Task.Delay(1000, cancellationToken);
11 | return "irrelevant";
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Chapter12/TupleLiteralDeconstruction.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 |
4 | namespace Chapter12
5 | {
6 | [Description("Snippet in section 10.1.3")]
7 | class TupleLiteralDeconstruction
8 | {
9 | static void Main()
10 | {
11 | (string text, Func func) = (null, x => x * 2);
12 | (text, func) = ("text", x => x * 3);
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Chapter03/ExpressionTreeIntro.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 | using System.Linq.Expressions;
4 |
5 | namespace Chapter03
6 | {
7 | [Description("Listing 3.12")]
8 | class ExpressionTreeIntro
9 | {
10 | static void Main()
11 | {
12 | Expression> adder = (x, y) => x + y;
13 | Console.WriteLine(adder);
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Chapter09Net40/FormattableStringFactory.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 |
3 | namespace System.Runtime.CompilerServices
4 | {
5 | [Description("Listing 9.10 (first half)")]
6 | internal static class FormattableStringFactory
7 | {
8 | internal static FormattableString Create(
9 | string format, params object[] arguments) =>
10 | new FormattableString(format, arguments);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Chapter03/Chapter03.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | netcoreapp2.0
5 | Chapter03.Program
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Chapter09/Chapter09.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | net462
5 | Chapter09.Program
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Chapter14/LocalMethodInLoop.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Chapter14
4 | {
5 | class LocalMethodInLoop
6 | {
7 | static void Main()
8 | {
9 | for (int i = 0; i < 10; i++)
10 | {
11 | PrintI();
12 |
13 | void PrintI()
14 | {
15 | Console.WriteLine(i);
16 | }
17 | }
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Chapter05/AsyncEntryPoint.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 | using System.Threading.Tasks;
4 |
5 | namespace Chapter05
6 | {
7 | [Description("Listing 5.11")]
8 | class AsyncEntryPoint
9 | {
10 | static async Task Main()
11 | {
12 | Console.WriteLine("Before delay");
13 | await Task.Delay(1000);
14 | Console.WriteLine("After delay");
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Chapter13/RefReturnNoLocal.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Chapter13
4 | {
5 | class RefReturnAsRefArgument
6 | {
7 | static void Main()
8 | {
9 | int x = 10;
10 | RefReturn(ref RefReturn(ref RefReturn(ref x)))++;
11 | Console.WriteLine(x);
12 | }
13 |
14 | static ref int RefReturn(ref int p)
15 | {
16 | return ref p;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Chapter04/Chapter04.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | netcoreapp2.0
5 | Chapter04.Program
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Chapter13/NoParameterCopy.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Chapter13
6 | {
7 | class NoParameterCopy
8 | {
9 | public void PrintYearMonthDay(YearMonthDay input)
10 | {
11 | int year = input.Year;
12 | int month = input.Month;
13 | int day = input.Day;
14 | Console.WriteLine($"{year} {month} {day}");
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Chapter14/DefaultLiteralOptionalParameter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 |
4 | namespace Chapter14
5 | {
6 | [Description("Listing 14.11")]
7 | class DefaultLiteralOptionalParameter
8 | {
9 | static void PrintValue(int value = 10)
10 | {
11 | Console.WriteLine(value);
12 | }
13 |
14 | static void Main()
15 | {
16 | PrintValue(default);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Chapter13/Vector3DExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Chapter13
4 | {
5 | public static class Vector3DExtensions
6 | {
7 | public static double Magnitude(this in Vector3D vec) =>
8 | Math.Sqrt(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z);
9 |
10 | public static void OffsetBy(this ref Vector3D orig, in Vector3D off) =>
11 | orig = new Vector3D(orig.X + off.X, orig.Y + off.Y, orig.Z + off.Z);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Chapter14/LocalMethodVariableCapture1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 |
4 | namespace Chapter14
5 | {
6 | [Description("Listing 14.2")]
7 | class LocalMethodVariableCapture1
8 | {
9 | static void Main()
10 | {
11 | int i = 0;
12 | AddToI(5);
13 | AddToI(10);
14 | Console.WriteLine(i);
15 | void AddToI(int amount) => i += amount;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter02/Chapter02.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | netcoreapp2.0
5 | Chapter02.Program
6 | 7.3
7 | True
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Chapter13/RefLocalIdentityConversions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 |
4 | namespace Chapter13
5 | {
6 | [Description("Listing 13.5")]
7 | class RefLocalIdentityConversions
8 | {
9 | static void Main()
10 | {
11 | (int x, int y) tuple1 = (10, 20);
12 | ref (int a, int b) tuple2 = ref tuple1;
13 | tuple2.a = 30;
14 | Console.WriteLine(tuple1.x);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Chapter02/IteratorBlockWithFinallyDemo1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 |
4 | namespace Chapter02
5 | {
6 | [Description("Listing 2.15")]
7 | class IteratorBlockWithFinallyDemo1
8 | {
9 | static void Main()
10 | {
11 | foreach (string value in IteratorBlockWithFinally.Iterator())
12 | {
13 | Console.WriteLine("Received value: {0}", value);
14 | }
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Chapter04/DynamicAddition.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 |
4 | namespace Chapter04
5 | {
6 | [Description("Listing 4.2")]
7 | class DynamicAddition
8 | {
9 | static void Add(dynamic d)
10 | {
11 | Console.WriteLine(d + d);
12 | }
13 |
14 | static void Main()
15 | {
16 | Add("text");
17 | Add(10);
18 | Add(TimeSpan.FromMinutes(45));
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter13/Chapter13.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 | Chapter13.Program
7 | latest
8 | true
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Chapter11/Chapter11.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.0
6 | Chapter11.Program
7 | latest
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Chapter13/RefReturnSimpleNoLocal.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 |
4 | namespace Chapter13
5 | {
6 | [Description("Listing 13.7")]
7 | class RefReturnSimpleNoLocal
8 | {
9 | static void Main()
10 | {
11 | int x = 10;
12 | RefReturn(ref x)++;
13 | Console.WriteLine(x);
14 | }
15 |
16 | static ref int RefReturn(ref int p)
17 | {
18 | return ref p;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Chapter14/Chapter14.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.0
6 | Chapter14.Program
7 | 7.3
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Chapter04/DynamicTypingIntro.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 |
4 | namespace Chapter04
5 | {
6 | [Description("Listing 4.1")]
7 | class DynamicTypingIntro
8 | {
9 | static void Main()
10 | {
11 | dynamic text = "hello world";
12 | string world = text.Substring(6);
13 | Console.WriteLine(world);
14 |
15 | string broken = text.SUBSTR(6);
16 | Console.WriteLine(broken);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Chapter12/Chapter12.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.0
6 | Chapter12.Program
7 | latest
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Chapter09/FormatPriceInterpolatedVerbatim.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 |
4 | namespace Chapter09
5 | {
6 | [Description("Listing 9.4")]
7 | public class FormatPriceInterpolatedVerbatim
8 | {
9 | static void Main()
10 | {
11 | decimal price = 95.25m;
12 | decimal tip = price * 0.2m;
13 | Console.WriteLine($@"Price: {price,9:C}
14 | Tip: {tip,9:C}
15 | Total: {price + tip,9:C}");
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Chapter13/RefReadonly.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 |
4 | namespace Chapter13
5 | {
6 | [Description("Listing 13.10")]
7 | class RefReadonly
8 | {
9 | private static readonly int field = DateTime.UtcNow.Second;
10 |
11 | static ref readonly int GetFieldAlias() => ref field;
12 |
13 | static void Main()
14 | {
15 | ref readonly int local = ref GetFieldAlias();
16 | Console.WriteLine(local);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Chapter04/LinqCovariance.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.ComponentModel;
3 | using System.Linq;
4 |
5 | namespace Chapter04
6 | {
7 | [Description("Listing 4.20")]
8 | class LinqCovariance
9 | {
10 | static void Main()
11 | {
12 | IEnumerable strings = new[] { "a", "b", "cdefg", "hij" };
13 | List