├── .gitattributes ├── Q04 ├── CommonLibrary │ ├── CommonLibrary.csproj │ └── Messages.cs ├── NetCoreApp │ ├── NetCoreApp.csproj │ └── Program.cs ├── NetFrameworkApp │ ├── App.config │ ├── NetFrameworkApp.csproj │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── NetFrameworkLibrary │ ├── Messages.cs │ ├── NetFrameworkLibrary.csproj │ └── Properties │ │ └── AssemblyInfo.cs ├── Q04.sln └── README.md ├── Q07 ├── Q07.sln └── VersionCompatibility │ ├── Program.cs │ └── VersionCompatibility.csproj ├── Q11 ├── Q11.sln └── ValueAndReferenceTypes │ ├── Program.cs │ ├── ReferenceTypes.cs │ ├── ValueAndReferenceTypes.csproj │ └── ValueTypes.cs ├── Q12 ├── Classes │ ├── Classes.csproj │ ├── Point.cs │ └── Program.cs ├── ImmutableStructs │ ├── ImmutableStructs.csproj │ ├── Point.cs │ └── Program.cs ├── Q12.sln └── Structs │ ├── Point.cs │ ├── Program.cs │ └── Structs.csproj ├── Q13 ├── BoxingExamples │ ├── BoxingExamples.csproj │ ├── Point.cs │ └── Program.cs ├── BoxingInterface │ ├── BoxingInterface.csproj │ ├── IPoint.cs │ ├── Point.cs │ └── Program.cs ├── BoxingStruct │ ├── BoxingStruct.csproj │ ├── Point.cs │ └── Program.cs └── Q13.sln ├── Q14 ├── NullableTypes │ ├── NullableTypes.csproj │ └── Program.cs └── Q14.sln ├── Q15 ├── EnumerationTypes │ ├── BinaryLiterals │ │ └── DayOfWeek.cs │ ├── EnumerationTypes.csproj │ ├── ExplicitValues │ │ └── DayOfWeek.cs │ ├── Flags │ │ └── DayOfWeek.cs │ ├── ImplicitValues │ │ └── DayOfWeek.cs │ ├── LargeValues.cs │ ├── Program.cs │ └── Quantity.cs └── Q15.sln ├── Q16 ├── MultiDimensionalData │ ├── MultiDimensionalData.csproj │ └── Program.cs └── Q16.sln ├── Q17 ├── Operators │ ├── ChangeNotifierNew.cs │ ├── ChangeNotifierOld.cs │ ├── Operators.csproj │ └── Program.cs └── Q17.sln ├── Q18 ├── ParametersByReference │ ├── ParametersByReference.csproj │ ├── Point.cs │ └── Program.cs └── Q18.sln ├── Q19 ├── AnonymousTypes │ ├── AnonymousTypes.csproj │ ├── Person.cs │ ├── Program.cs │ ├── SourceAddress.cs │ └── SourcePerson.cs └── Q19.sln ├── Q20 ├── Q20.sln └── TypeSafety │ ├── Circle.cs │ ├── IGeometricShape.cs │ ├── Program.cs │ ├── Square.cs │ └── TypeSafety.csproj ├── Q21 ├── DynamicBinding │ ├── DynamicBinding.csproj │ ├── MyDynamicObject.cs │ └── Program.cs └── Q21.sln ├── Q22 ├── Polymorphism │ ├── Bow.cs │ ├── Enemy.cs │ ├── IEnemy.cs │ ├── IWeapon.cs │ ├── Player.cs │ ├── PoisonedSword.cs │ ├── Polymorphism.csproj │ ├── Program.cs │ └── Sword.cs └── Q22.sln ├── Q23 ├── AccessibilityLevels │ ├── AccessibilityLevels.csproj │ ├── ExternallyVisibleType.cs │ ├── HiddenType.cs │ ├── InternalsVisibleTo.cs │ ├── Program.cs │ ├── SampleEnum.cs │ ├── SampleInterface.cs │ └── SampleType.cs ├── Q23.sln └── TestAssembly │ ├── Program.cs │ └── TestAssembly.csproj ├── Q24 ├── AbstractClasses │ ├── AbstractClasses.csproj │ ├── ISampleInterface.cs │ ├── Program.cs │ ├── SampleAbstractClass.cs │ ├── SampleClass.cs │ └── SampleImplementingClass.cs └── Q24.sln ├── Q25 ├── ExplicitlyImplementedInterface │ ├── ClassMemberAndExplicitImplementation.cs │ ├── ExplicitImplementation.cs │ ├── ExplicitTwoInterfaces.cs │ ├── ExplicitlyImplementedInterface.csproj │ ├── ISecondInterface.cs │ ├── ISimpleInterface.cs │ ├── ImplicitImplementation.cs │ ├── ImplicitTwoInterfaces.cs │ └── Program.cs └── Q25.sln ├── Q26 ├── NewModifier │ ├── BaseClass.cs │ ├── DerivedClass.cs │ ├── NewModifier.csproj │ ├── NewModifierClass.cs │ ├── NonVIrtualBaseClass.cs │ ├── NonVirtualDerivedClass.cs │ └── Program.cs └── Q26.sln ├── Q27 ├── EqualsMethod │ ├── CustomEquals │ │ └── PointClass.cs │ ├── CustomEqualsAndGetHashCode │ │ └── PointClass.cs │ ├── EqualsMethod.csproj │ ├── Equatable │ │ └── PointClass.cs │ ├── NoCustomEquals │ │ ├── PointClass.cs │ │ └── PointStruct.cs │ └── Tests.cs └── Q27.sln ├── Q28 ├── OperatorOverloading │ ├── ComplexNumber.cs │ ├── OperatorOverloading.csproj │ └── Program.cs └── Q28.sln ├── Q29 ├── DelegatesAndEvents │ ├── DelegatesAndEvents.csproj │ ├── InstrumentedNotifyingClass.cs │ ├── MethodEventArgs.cs │ ├── NotifyingClass.cs │ └── Program.cs └── Q29.sln ├── Q30 ├── IDisposableInterface │ ├── DisposableClass.cs │ ├── IDisposableInterface.csproj │ ├── Program.cs │ ├── TextFile1.txt │ └── TextFile2.txt └── Q30.sln ├── Q31 ├── Finalizers │ ├── ClassWithFinalizer.cs │ ├── ClassWithSafeHandle.cs │ ├── Finalizers.csproj │ └── Program.cs ├── Q31.sln └── README.md ├── Q32 ├── Q32.sln └── StaticMembers │ ├── ClassNamespace │ └── FibonacciNumberCalculator.cs │ ├── ClassWithInstanceMembers.cs │ ├── Config.cs │ ├── FailingClass.cs │ ├── FibonacciNumberCalculator.cs │ ├── GenericClass.cs │ ├── Program.cs │ └── StaticMembers.csproj ├── Q33 ├── ExtensionMethods │ ├── ExtensionMethods.csproj │ ├── Program.cs │ └── StringExtensions.cs └── Q33.sln ├── Q34 ├── AutoImplementedProperties │ ├── AutoImplementedProperties.csproj │ ├── DerivedClass.cs │ ├── Program.cs │ └── SampleClass.cs └── Q34.sln ├── Q35 ├── ExpressionBodiedMembers │ ├── ExpressionBodiedMembers.csproj │ ├── ExpressionBody │ │ └── Student.cs │ ├── Program.cs │ └── RegularBody │ │ └── Student.cs └── Q35.sln ├── Q36 ├── InterpolatedStrings │ ├── EFContext.cs │ ├── InterpolatedStrings.csproj │ ├── Person.cs │ ├── Program.cs │ └── Properties │ │ └── Strings.cs └── Q36.sln ├── Q37 ├── LocaleStringManipulation │ ├── LocaleStringManipulation.csproj │ └── Program.cs └── Q37.sln ├── Q38 ├── Q38.sln └── StringManipulation │ ├── Program.cs │ └── StringManipulation.csproj ├── Q39 ├── GenericCodeImprovements │ ├── GenericCodeImprovements.csproj │ └── Program.cs └── Q39.sln ├── Q40 ├── ImplementGenerics │ ├── GenericComparer.cs │ ├── ImplementGenerics.csproj │ ├── IntComparer.cs │ └── Program.cs └── Q40.sln ├── Q41 ├── GenericTypeConstraints │ ├── Extensions.cs │ ├── FuelType.cs │ ├── GenericTypeConstraints.csproj │ ├── IPerson.cs │ ├── Member.cs │ ├── PersonClass.cs │ ├── PersonStruct.cs │ └── Program.cs └── Q41.sln ├── Q42 ├── CovarianceContravariance │ ├── CovarianceContravariance.csproj │ ├── IVariant.cs │ └── Program.cs └── Q42.sln ├── Q43 ├── IEnumerableInterface │ ├── IEnumerableInterface.csproj │ ├── NoIEnumerable.cs │ └── Program.cs └── Q43.sln ├── Q44 ├── ImplementIEnumerable │ ├── ArrayWrapper.cs │ ├── ImplementIEnumerable.csproj │ └── Program.cs └── Q44.sln ├── Q45 ├── ArraysAndCollections │ ├── ArraysAndCollections.csproj │ └── Program.cs └── Q45.sln ├── Q46 ├── CollectionClasses │ ├── CollectionClasses.csproj │ └── Program.cs └── Q46.sln ├── Q47 ├── ConcurrentCollections │ ├── ConcurrentCollections.csproj │ ├── DictionaryWithLock.cs │ ├── DictionaryWithReaderWriterLock.cs │ ├── ExpensiveResource.cs │ └── Program.cs └── Q47.sln ├── Q48 ├── ImmutableCollections │ ├── ImmutableCollections.csproj │ └── Program.cs └── Q48.sln ├── Q49 ├── LinqStructure │ ├── LinqStructure.csproj │ ├── Person.cs │ └── Program.cs └── Q49.sln ├── Q50 ├── LinqMethodSyntax │ ├── LinqMethodSyntax.csproj │ ├── Person.cs │ ├── Program.cs │ └── Room.cs └── Q50.sln ├── Q51 ├── LinqJoins │ ├── LinqJoins.csproj │ ├── Program.cs │ ├── Registration.cs │ ├── Student.cs │ └── StudentGrade.cs └── Q51.sln ├── Q52 ├── LinqSetOperations │ ├── LinqSetOperations.csproj │ ├── Person.cs │ ├── PersonComparer.cs │ └── Program.cs └── Q52.sln ├── Q53 ├── LinqAggregation │ ├── LinqAggregation.csproj │ ├── Person.cs │ └── Program.cs └── Q53.sln ├── Q54 ├── LinqGrouping │ ├── LinqGrouping.csproj │ └── Program.cs └── Q54.sln ├── Q55 ├── LinqDeferredExecution │ ├── LinqDeferredExecution.csproj │ └── Program.cs └── Q55.sln ├── Q56 ├── LinqQueryExecution │ ├── Extensions │ │ └── EnumerableExtensions.cs │ ├── LinqQueryExecution.csproj │ ├── Migrations │ │ ├── 20190119102455_InitialCreate.Designer.cs │ │ ├── 20190119102455_InitialCreate.cs │ │ └── PersonContextModelSnapshot.cs │ ├── Person.cs │ ├── PersonContext.cs │ ├── Persons.db │ ├── Program.CustomExtensions.cs │ └── Program.cs └── Q56.sln ├── Q57 ├── LinqQueryExecution │ ├── LinqQueryExecution.csproj │ ├── Person.cs │ ├── PersonContext.cs │ └── Program.cs └── Q57.sln ├── Q58 ├── Q58.sln └── QueryableVsEnumerable │ ├── Migrations │ ├── 20190119105807_InitialCreate.Designer.cs │ ├── 20190119105807_InitialCreate.cs │ └── PersonContextModelSnapshot.cs │ ├── Person.cs │ ├── PersonContext.cs │ ├── Persons.db │ ├── Program.cs │ ├── QueryableVsEnumerable.csproj │ └── RepositoryExtensions.cs ├── Q59 ├── ConcurrentMultithreadedAsynchronous │ ├── ConcurrentMultithreadedAsynchronous.csproj │ ├── Program.cs │ └── TextFile1.txt └── Q59.sln ├── Q60 ├── Q60.sln ├── README.md ├── Timers │ ├── Program.cs │ └── Timers.csproj ├── WindowsFormsTimer │ ├── App.config │ ├── Form1.Designer.cs │ ├── Form1.cs │ ├── Form1.resx │ ├── Program.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ └── WindowsFormsTimer.csproj └── WpfTimer │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings │ └── WpfTimer.csproj ├── Q61 ├── AbortingThreads │ ├── AbortingThreads.csproj │ ├── App.config │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── Q61.sln ├── README.md └── Threads │ ├── Program.cs │ └── Threads.csproj ├── Q62 ├── MultithreadingAbstractions │ ├── MultithreadingAbstractions.csproj │ └── Program.cs └── Q62.sln ├── Q63 ├── Q63.sln └── TaskBasedAsynchronousModel │ ├── Program.cs │ ├── TaskBasedAsynchronousModel.csproj │ └── src.txt ├── Q64 ├── AsynchronousProgrammingModel │ ├── AsynchronousProgrammingModel.csproj │ ├── Program.cs │ └── TextFile1.txt └── Q64.sln ├── Q65 ├── EventBasedAsynchronousPattern │ ├── EventBasedAsynchronousPattern.csproj │ └── Program.cs └── Q65.sln ├── Q66 ├── AsyncAwaitCodeExecution │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── AsyncAwaitCodeExecution.csproj │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ └── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings ├── Q66.sln └── README.md ├── Q67 ├── AsyncInExistingCode │ ├── AsyncInExistingCode.csproj │ └── Program.cs ├── NewConsoleApp │ ├── NewConsoleApp.csproj │ └── Program.cs ├── OldConsoleApp │ ├── OldConsoleApp.csproj │ └── Program.cs ├── Q67.sln ├── README.md ├── WebApplication │ ├── Controllers │ │ └── HomeController.cs │ ├── Models │ │ └── ErrorViewModel.cs │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Startup.cs │ ├── Views │ │ ├── Home │ │ │ ├── Index.cshtml │ │ │ └── Privacy.cshtml │ │ ├── Shared │ │ │ ├── Error.cshtml │ │ │ ├── _CookieConsentPartial.cshtml │ │ │ ├── _Layout.cshtml │ │ │ └── _ValidationScriptsPartial.cshtml │ │ ├── _ViewImports.cshtml │ │ └── _ViewStart.cshtml │ ├── WebApplication.csproj │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ │ ├── css │ │ └── site.css │ │ ├── favicon.ico │ │ ├── js │ │ └── site.js │ │ └── lib │ │ ├── bootstrap │ │ ├── LICENSE │ │ └── dist │ │ │ ├── css │ │ │ ├── bootstrap-grid.css │ │ │ ├── bootstrap-grid.css.map │ │ │ ├── bootstrap-grid.min.css │ │ │ ├── bootstrap-grid.min.css.map │ │ │ ├── bootstrap-reboot.css │ │ │ ├── bootstrap-reboot.css.map │ │ │ ├── bootstrap-reboot.min.css │ │ │ ├── bootstrap-reboot.min.css.map │ │ │ ├── bootstrap.css │ │ │ ├── bootstrap.css.map │ │ │ ├── bootstrap.min.css │ │ │ └── bootstrap.min.css.map │ │ │ └── js │ │ │ ├── bootstrap.bundle.js │ │ │ ├── bootstrap.bundle.js.map │ │ │ ├── bootstrap.bundle.min.js │ │ │ ├── bootstrap.bundle.min.js.map │ │ │ ├── bootstrap.js │ │ │ ├── bootstrap.js.map │ │ │ ├── bootstrap.min.js │ │ │ └── bootstrap.min.js.map │ │ ├── jquery-validation-unobtrusive │ │ ├── LICENSE.txt │ │ ├── jquery.validate.unobtrusive.js │ │ └── jquery.validate.unobtrusive.min.js │ │ ├── jquery-validation │ │ ├── LICENSE.md │ │ └── dist │ │ │ ├── additional-methods.js │ │ │ ├── additional-methods.min.js │ │ │ ├── jquery.validate.js │ │ │ └── jquery.validate.min.js │ │ └── jquery │ │ ├── LICENSE.txt │ │ └── dist │ │ ├── jquery.js │ │ ├── jquery.min.js │ │ └── jquery.min.map └── WpfApp │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings │ └── WpfApp.csproj ├── Q68 ├── AsyncPitfalls │ ├── AsyncPitfalls.csproj │ └── Program.cs ├── Q68.sln ├── README.md └── WpfApp │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── InnocentLookingClass.cs │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings │ └── WpfApp.csproj ├── Q69 ├── AsyncExceptions │ ├── AsyncExceptions.csproj │ └── Program.cs └── Q69.sln ├── Q70 ├── AsyncFileOperations │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── AsyncFileOperations.csproj │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ └── TextFile1.txt ├── Q70.sln └── README.md ├── Q71 ├── CriticalSection │ ├── BankAccount.cs │ ├── CriticalSection.csproj │ └── Program.cs └── Q71.sln ├── Q72 ├── Q72.sln └── ThreadSynchronization │ ├── BankAccount.cs │ ├── DictionaryWithReaderWriterLock.cs │ ├── Program.cs │ └── ThreadSynchronization.csproj ├── Q73 ├── Q73.sln └── Serialization │ ├── Bow.cs │ ├── Hero.cs │ ├── IWeapon.cs │ ├── Node.cs │ ├── Person.cs │ ├── PersonCustomized.cs │ ├── PersonNoAttributes.cs │ ├── PersonWithAttributes.cs │ ├── Program.cs │ ├── SerializablePerson.cs │ └── Serialization.csproj ├── Q74 ├── Plugins │ ├── CustomPlugin.cs │ ├── IPlugin.cs │ └── Plugins.csproj ├── Q74.sln └── Reflection │ ├── Program.cs │ └── Reflection.csproj ├── Q75 ├── AddOns │ ├── AddOns.csproj │ └── Pluggable.cs ├── Contracts │ ├── Contracts.csproj │ └── IPluggable.cs ├── Q75.sln └── ReflectionDangers │ ├── IQeryableExtensions.cs │ ├── Program.cs │ └── ReflectionDangers.csproj ├── Q76 ├── CustomAttributes │ ├── CustomAttributes.csproj │ ├── IValidatable.cs │ ├── NotNullableAttribute.cs │ ├── Person.cs │ ├── Program.cs │ ├── ValidatablePerson.cs │ └── ValidationExtensions.cs └── Q76.sln ├── Q77 ├── CSharp2 │ ├── CSharp2.csproj │ ├── IntList.cs │ └── Program.cs ├── CSharp3 │ ├── CSharp3.csproj │ ├── NameAndAge.cs │ ├── Person.cs │ └── Program.cs ├── CSharp4 │ ├── CSharp4.csproj │ └── Program.cs ├── CSharp5 │ ├── CSharp5.csproj │ ├── Program.cs │ └── TextFile1.txt ├── CSharp6 │ ├── CSharp6.csproj │ └── Program.cs ├── CSharp7 │ ├── Bow.cs │ ├── CSharp7.csproj │ ├── Enemy.cs │ ├── IEnemy.cs │ ├── IWeapon.cs │ ├── Inventory.cs │ ├── Program.cs │ └── Sword.cs └── Q77.sln ├── Q78 ├── BestCs6Features │ ├── AsyncResource.cs │ ├── BestCs6Features.csproj │ ├── Program.cs │ └── PropertyChangeNotifier.cs └── Q78.sln ├── Q79 ├── Q79.sln └── Tuples │ ├── IWeapon.cs │ ├── Person.cs │ ├── PersonExtensions.cs │ ├── Program.cs │ └── Tuples.csproj ├── Q80 ├── LocalFunctions │ ├── LocalFunctions.csproj │ └── Program.cs └── Q80.sln ├── Q81 ├── PatternMatching │ ├── Bow.cs │ ├── Enemy.cs │ ├── IEnemy.cs │ ├── IWeapon.cs │ ├── PatternMatching.csproj │ ├── Program.cs │ └── Sword.cs └── Q81.sln ├── Q82 ├── Discards │ ├── Bow.cs │ ├── Discards.csproj │ ├── IWeapon.cs │ ├── Person.cs │ ├── Program.cs │ └── Sword.cs └── Q82.sln ├── Q83 ├── AsyncMain │ ├── AsyncMain.csproj │ └── Program.cs ├── AsyncValueTask │ ├── AsyncValueTask.csproj │ └── Program.cs ├── Q83.sln └── SyncMain │ ├── Program.cs │ └── SyncMain.csproj ├── Q84 ├── Q84.sln └── ValuesByReference │ ├── ReadOnlyStruct.cs │ ├── Terrain.cs │ ├── TerrainType.cs │ ├── Tests.cs │ ├── ValuesByReference.csproj │ └── Vector3.cs ├── Q85 ├── ErrorHandling │ ├── ErrorHandling.csproj │ └── Program.cs ├── Q85.sln ├── README.md ├── WebApp │ ├── App_Start │ │ ├── BundleConfig.cs │ │ ├── FilterConfig.cs │ │ └── RouteConfig.cs │ ├── Content │ │ ├── Site.css │ │ ├── bootstrap-theme.css │ │ ├── bootstrap-theme.css.map │ │ ├── bootstrap-theme.min.css │ │ ├── bootstrap-theme.min.css.map │ │ ├── bootstrap.css │ │ ├── bootstrap.css.map │ │ ├── bootstrap.min.css │ │ └── bootstrap.min.css.map │ ├── Controllers │ │ ├── ErrorController.cs │ │ └── HomeController.cs │ ├── Global.asax │ ├── Global.asax.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Scripts │ │ ├── bootstrap.js │ │ ├── bootstrap.min.js │ │ ├── jquery-3.3.1.intellisense.js │ │ ├── jquery-3.3.1.js │ │ ├── jquery-3.3.1.min.js │ │ ├── jquery-3.3.1.min.map │ │ ├── jquery-3.3.1.slim.js │ │ ├── jquery-3.3.1.slim.min.js │ │ ├── jquery-3.3.1.slim.min.map │ │ ├── jquery.validate-vsdoc.js │ │ ├── jquery.validate.js │ │ ├── jquery.validate.min.js │ │ ├── jquery.validate.unobtrusive.js │ │ ├── jquery.validate.unobtrusive.min.js │ │ └── modernizr-2.8.3.js │ ├── Views │ │ ├── Error │ │ │ └── Index.cshtml │ │ ├── Home │ │ │ ├── About.cshtml │ │ │ ├── Contact.cshtml │ │ │ └── Index.cshtml │ │ ├── Shared │ │ │ ├── Error.cshtml │ │ │ └── _Layout.cshtml │ │ ├── Web.config │ │ └── _ViewStart.cshtml │ ├── Web.Debug.config │ ├── Web.Release.config │ ├── Web.config │ ├── WebApp.csproj │ ├── WebApp.csproj.user │ ├── favicon.ico │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.svg │ │ ├── glyphicons-halflings-regular.ttf │ │ ├── glyphicons-halflings-regular.woff │ │ └── glyphicons-halflings-regular.woff2 │ └── packages.config ├── WindowsFormsApp │ ├── App.config │ ├── Form1.Designer.cs │ ├── Form1.cs │ ├── Form1.resx │ ├── PersonEntity.cs │ ├── PersonModel.cs │ ├── Program.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ └── WindowsFormsApp.csproj └── WpfApp │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings │ └── WpfApp.csproj ├── Q86 ├── FunctionalProgramming │ ├── FunctionalProgramming.csproj │ ├── Person.cs │ ├── PersonExtensions.cs │ └── Tests.cs └── Q86.sln ├── Q87 ├── Cs8Features │ ├── AsyncEnumerableBoilerPlate.cs │ ├── Cs8Features.csproj │ ├── IWeapon.cs │ └── Tests.cs ├── Q87.sln └── README.md └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Q04/CommonLibrary/CommonLibrary.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Q04/CommonLibrary/Messages.cs: -------------------------------------------------------------------------------- 1 | namespace CommonLibrary 2 | { 3 | public class Messages 4 | { 5 | public string Hello(string name = "World") 6 | { 7 | return $"Hello {name} from .NET Standard!"; 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Q04/NetCoreApp/NetCoreApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Q04/NetCoreApp/Program.cs: -------------------------------------------------------------------------------- 1 | using NetFrameworkLibrary; 2 | using System; 3 | 4 | namespace NetCoreApp 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | var messages = new Messages(); 11 | Console.WriteLine(messages.Hello(".NET Core")); 12 | Console.ReadLine(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Q04/NetFrameworkApp/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Q04/NetFrameworkApp/Program.cs: -------------------------------------------------------------------------------- 1 | using CommonLibrary; 2 | using System; 3 | 4 | namespace NetFrameworkApp 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | var messages = new Messages(); 11 | Console.WriteLine(messages.Hello(".NET Framework")); 12 | Console.ReadLine(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Q04/NetFrameworkLibrary/Messages.cs: -------------------------------------------------------------------------------- 1 | namespace NetFrameworkLibrary 2 | { 3 | public class Messages 4 | { 5 | public string Hello(string name = "World") 6 | { 7 | return $"Hello {name} from .NET Framework!"; 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Q04/README.md: -------------------------------------------------------------------------------- 1 | This example is Windows specific and requires Visual Studio 2017 to run because `NetFrameworkApp` and `NetFrameworkLibrary` are .NET framework projects. -------------------------------------------------------------------------------- /Q07/VersionCompatibility/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | 4 | namespace VersionCompatibility 5 | { 6 | class Program 7 | { 8 | public static void LogMessage(string message, 9 | [CallerMemberName] string memberName = "", 10 | [CallerFilePath] string sourceFilePath = "", 11 | [CallerLineNumber] int sourceLineNumber = 0) 12 | { 13 | // logging implementation 14 | Console.WriteLine($"{memberName} ({sourceFilePath}, {sourceLineNumber}): {message}"); 15 | } 16 | 17 | static void Main(string[] args) 18 | { 19 | LogMessage("Hello"); 20 | Console.ReadLine(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Q07/VersionCompatibility/VersionCompatibility.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q11/ValueAndReferenceTypes/Program.cs: -------------------------------------------------------------------------------- 1 | namespace ValueAndReferenceTypes 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | ValueTypes.Method1(); 8 | ReferenceTypes.Method1(); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Q11/ValueAndReferenceTypes/ReferenceTypes.cs: -------------------------------------------------------------------------------- 1 | namespace ValueAndReferenceTypes 2 | { 3 | class ReferenceTypes 4 | { 5 | public static void Method1() 6 | { 7 | var a = "1"; 8 | Method2(a); 9 | } 10 | 11 | static void Method2(string a) 12 | { 13 | a = "2"; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Q11/ValueAndReferenceTypes/ValueAndReferenceTypes.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q11/ValueAndReferenceTypes/ValueTypes.cs: -------------------------------------------------------------------------------- 1 | namespace ValueAndReferenceTypes 2 | { 3 | class ValueTypes 4 | { 5 | public static void Method1() 6 | { 7 | var a = 1; 8 | Method2(a); 9 | } 10 | 11 | static void Method2(int a) 12 | { 13 | a = 2; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Q12/Classes/Classes.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q12/Classes/Point.cs: -------------------------------------------------------------------------------- 1 | namespace Classes 2 | { 3 | class Point 4 | { 5 | public int x; 6 | public int y; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Q12/ImmutableStructs/ImmutableStructs.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q12/ImmutableStructs/Point.cs: -------------------------------------------------------------------------------- 1 | namespace ImmutableStructs 2 | { 3 | struct Point 4 | { 5 | public Point(int x, int y) 6 | { 7 | X = x; 8 | Y = y; 9 | } 10 | 11 | public int X { get; private set; } 12 | public int Y { get; private set; } 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Q12/Structs/Point.cs: -------------------------------------------------------------------------------- 1 | namespace Structs 2 | { 3 | struct Point 4 | { 5 | public int x; 6 | public int y; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Q12/Structs/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Structs 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Method1(); 10 | Console.ReadLine(); 11 | } 12 | 13 | static void Method1() 14 | { 15 | var a = new Point(); 16 | Console.WriteLine($"Method1 - start: x = {a.x}, y = {a.y}"); 17 | Method2(a); 18 | Console.WriteLine($"Method1 - end: x = {a.x}, y = {a.y}"); 19 | } 20 | 21 | static void Method2(Point a) 22 | { 23 | Console.WriteLine($"Method2 - start: x = {a.x}, y = {a.y}"); 24 | a.x = 1; 25 | Console.WriteLine($"Method2 - end: x = {a.x}, y = {a.y}"); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Q12/Structs/Structs.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q13/BoxingExamples/BoxingExamples.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q13/BoxingExamples/Point.cs: -------------------------------------------------------------------------------- 1 | namespace BoxingExamples 2 | { 3 | struct Point 4 | { 5 | public int X { get; set; } 6 | public int Y { get; set; } 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Q13/BoxingInterface/BoxingInterface.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q13/BoxingInterface/IPoint.cs: -------------------------------------------------------------------------------- 1 | namespace BoxingInterface 2 | { 3 | interface IPoint 4 | { 5 | int X { get; set; } 6 | int Y { get; set; } 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Q13/BoxingInterface/Point.cs: -------------------------------------------------------------------------------- 1 | namespace BoxingInterface 2 | { 3 | struct Point : IPoint 4 | { 5 | public int X { get; set; } 6 | public int Y { get; set; } 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Q13/BoxingInterface/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BoxingInterface 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Point p = new Point(); 10 | IPoint i1 = p; 11 | IPoint i2 = i1; 12 | i1.X = 1; 13 | Console.WriteLine($"p.X = {p.X}"); 14 | Console.WriteLine($"i1.X = {i1.X}"); 15 | Console.WriteLine($"i2.X = {i2.X}"); 16 | } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Q13/BoxingStruct/BoxingStruct.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q13/BoxingStruct/Point.cs: -------------------------------------------------------------------------------- 1 | namespace BoxingStruct 2 | { 3 | struct Point 4 | { 5 | public int X { get; set; } 6 | public int Y { get; set; } 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Q13/BoxingStruct/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BoxingStruct 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Point p = new Point(); 10 | object o = p; 11 | p.X = 1; 12 | Console.WriteLine($"p.X = {p.X}"); 13 | Console.WriteLine($"o.X = {((Point)o).X}"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Q14/NullableTypes/NullableTypes.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q14/Q14.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NullableTypes", "NullableTypes\NullableTypes.csproj", "{E5F84E59-775D-4295-93CC-E0E52C6363DA}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {E5F84E59-775D-4295-93CC-E0E52C6363DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {E5F84E59-775D-4295-93CC-E0E52C6363DA}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {E5F84E59-775D-4295-93CC-E0E52C6363DA}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {E5F84E59-775D-4295-93CC-E0E52C6363DA}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {01BF93EF-3992-4258-B25F-124FF93FD7A1} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q15/EnumerationTypes/BinaryLiterals/DayOfWeek.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EnumerationTypes.BinaryLiterals 4 | { 5 | [Flags] 6 | public enum DayOfWeek 7 | { 8 | None = 0b0, 9 | Monday = 0b1, 10 | Tuesday = 0b10, 11 | Wednesday = 0b100, 12 | Thursday = 0b1000, 13 | Friday = 0b1_0000, 14 | Saturday = 0b10_0000, 15 | Sunday = 0b100_0000, 16 | Weekday = Monday | Tuesday | Wednesday | Thursday | Friday, 17 | Weekend = Saturday | Sunday 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Q15/EnumerationTypes/EnumerationTypes.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q15/EnumerationTypes/ExplicitValues/DayOfWeek.cs: -------------------------------------------------------------------------------- 1 | namespace EnumerationTypes.ExplicitValues 2 | { 3 | public enum DayOfWeek 4 | { 5 | Monday = 1, 6 | Tuesday = 2, 7 | Wednesday = 3, 8 | Thursday = 4, 9 | Friday = 5, 10 | Saturday = 6, 11 | Sunday = 7 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Q15/EnumerationTypes/Flags/DayOfWeek.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EnumerationTypes.Flags 4 | { 5 | [Flags] 6 | public enum DayOfWeek 7 | { 8 | None = 0x0, 9 | Monday = 0x1, 10 | Tuesday = 0x2, 11 | Wednesday = 0x4, 12 | Thursday = 0x8, 13 | Friday = 0x10, 14 | Saturday = 0x20, 15 | Sunday = 0x40 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Q15/EnumerationTypes/ImplicitValues/DayOfWeek.cs: -------------------------------------------------------------------------------- 1 | namespace EnumerationTypes.ImplicitValues 2 | { 3 | public enum DayOfWeek 4 | { 5 | Monday, 6 | Tuesday, 7 | Wednesday, 8 | Thursday, 9 | Friday, 10 | Saturday, 11 | Sunday 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Q15/EnumerationTypes/LargeValues.cs: -------------------------------------------------------------------------------- 1 | namespace EnumerationTypes 2 | { 3 | public enum LargeValues : long 4 | { 5 | TenBillions = 10_000_000_000 6 | } 7 | 8 | } 9 | -------------------------------------------------------------------------------- /Q15/EnumerationTypes/Quantity.cs: -------------------------------------------------------------------------------- 1 | namespace EnumerationTypes 2 | { 3 | public enum Quantity 4 | { 5 | None, 6 | Few = 5, 7 | Six, 8 | Many = 100, 9 | Lots = 100 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Q16/MultiDimensionalData/MultiDimensionalData.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q17/Operators/ChangeNotifierNew.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace Operators 4 | { 5 | class ChangeNotifierNew : INotifyPropertyChanged 6 | { 7 | public event PropertyChangedEventHandler PropertyChanged; 8 | 9 | private void NotifyPropertyChanged(string propertyName) 10 | { 11 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Q17/Operators/ChangeNotifierOld.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace Operators 4 | { 5 | class ChangeNotifierOld : INotifyPropertyChanged 6 | { 7 | public event PropertyChangedEventHandler PropertyChanged; 8 | 9 | private void NotifyPropertyChanged(string propertyName) 10 | { 11 | var handler = PropertyChanged; 12 | if (handler != null) 13 | { 14 | handler.Invoke(this, new PropertyChangedEventArgs(propertyName)); 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Q17/Operators/Operators.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q17/Q17.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Operators", "Operators\Operators.csproj", "{3BCB8A5A-E820-452C-81C2-72E0E08C5CA0}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {3BCB8A5A-E820-452C-81C2-72E0E08C5CA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {3BCB8A5A-E820-452C-81C2-72E0E08C5CA0}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {3BCB8A5A-E820-452C-81C2-72E0E08C5CA0}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {3BCB8A5A-E820-452C-81C2-72E0E08C5CA0}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {30BA9E6B-68D9-46A5-8C11-083C939AFAA5} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q18/ParametersByReference/ParametersByReference.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q18/ParametersByReference/Point.cs: -------------------------------------------------------------------------------- 1 | namespace ParametersByReference 2 | { 3 | struct Point 4 | { 5 | public int X { get; set; } 6 | public int Y { get; set; } 7 | 8 | public Point(int x, int y) 9 | { 10 | X = x; 11 | Y = y; 12 | } 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Q19/AnonymousTypes/AnonymousTypes.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q19/AnonymousTypes/Person.cs: -------------------------------------------------------------------------------- 1 | namespace AnonymousTypes 2 | { 3 | internal sealed class Person 4 | { 5 | public string FirstName { get; } 6 | public string LastName { get; } 7 | 8 | public Person(string firstName, string lastName) 9 | { 10 | FirstName = firstName; 11 | LastName = lastName; 12 | } 13 | 14 | public override bool Equals(object obj) 15 | { 16 | var value = obj as Person; 17 | if (value == null) 18 | { 19 | return false; 20 | } 21 | 22 | return Equals(FirstName, value.FirstName) && Equals(LastName, value.LastName); 23 | } 24 | 25 | public override int GetHashCode() 26 | { 27 | return FirstName?.GetHashCode() ?? 0 ^ LastName?.GetHashCode() ?? 0; 28 | } 29 | 30 | public override string ToString() 31 | { 32 | return $"{{ FirstName = {FirstName}, LastName = {LastName} }}"; 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Q19/AnonymousTypes/SourceAddress.cs: -------------------------------------------------------------------------------- 1 | namespace AnonymousTypes 2 | { 3 | class SourceAddress 4 | { 5 | public string Country { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Q19/AnonymousTypes/SourcePerson.cs: -------------------------------------------------------------------------------- 1 | namespace AnonymousTypes 2 | { 3 | class SourcePerson 4 | { 5 | public string FirstName { get; set; } 6 | public string LastName { get; set; } 7 | public SourceAddress Address { get; set; } 8 | public SourcePerson Father { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Q19/Q19.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnonymousTypes", "AnonymousTypes\AnonymousTypes.csproj", "{CAAEA004-64BB-46F0-A5F4-754528400051}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {CAAEA004-64BB-46F0-A5F4-754528400051}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {CAAEA004-64BB-46F0-A5F4-754528400051}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {CAAEA004-64BB-46F0-A5F4-754528400051}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {CAAEA004-64BB-46F0-A5F4-754528400051}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {1866A8A6-435E-4A1D-8EB8-353DA2BE26CC} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q20/Q20.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypeSafety", "TypeSafety\TypeSafety.csproj", "{F3ECCF2E-5917-4B38-A126-80ED3A0BC72C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {F3ECCF2E-5917-4B38-A126-80ED3A0BC72C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {F3ECCF2E-5917-4B38-A126-80ED3A0BC72C}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {F3ECCF2E-5917-4B38-A126-80ED3A0BC72C}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {F3ECCF2E-5917-4B38-A126-80ED3A0BC72C}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {F3C67B25-A39C-4229-945C-5970C80064FD} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q20/TypeSafety/Circle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TypeSafety 4 | { 5 | public class Circle : IGeometricShape 6 | { 7 | public double Radius { get; set; } 8 | 9 | public double Circumference => 2 * Math.PI * Radius; 10 | 11 | public double Area => Math.PI * Radius * Radius; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Q20/TypeSafety/IGeometricShape.cs: -------------------------------------------------------------------------------- 1 | namespace TypeSafety 2 | { 3 | public interface IGeometricShape 4 | { 5 | double Circumference { get; } 6 | double Area { get; } 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Q20/TypeSafety/Square.cs: -------------------------------------------------------------------------------- 1 | namespace TypeSafety 2 | { 3 | public class Square : IGeometricShape 4 | { 5 | public double Side { get; set; } 6 | 7 | public double Circumference => 4 * Side; 8 | 9 | public double Area => Side * Side; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Q20/TypeSafety/TypeSafety.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | true 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Q21/DynamicBinding/DynamicBinding.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Q21/Q21.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DynamicBinding", "DynamicBinding\DynamicBinding.csproj", "{54349B01-4E58-4BBE-8223-2D0B06AB1D4F}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {54349B01-4E58-4BBE-8223-2D0B06AB1D4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {54349B01-4E58-4BBE-8223-2D0B06AB1D4F}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {54349B01-4E58-4BBE-8223-2D0B06AB1D4F}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {54349B01-4E58-4BBE-8223-2D0B06AB1D4F}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {E2A5009C-8AB3-451B-BC5D-F8DBE9F8C48C} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q22/Polymorphism/Bow.cs: -------------------------------------------------------------------------------- 1 | namespace Polymorphism 2 | { 3 | class Bow : IWeapon 4 | { 5 | public int Damage { get; set; } 6 | public int Arrows { get; set; } 7 | 8 | public void Attack(IEnemy enemy) 9 | { 10 | if (Arrows > 0) 11 | { 12 | enemy.Health -= Damage; 13 | Arrows--; 14 | } 15 | } 16 | 17 | public void Repair() 18 | { } 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Q22/Polymorphism/Enemy.cs: -------------------------------------------------------------------------------- 1 | namespace Polymorphism 2 | { 3 | class Enemy : IEnemy 4 | { 5 | public int Health { get; set; } 6 | public bool Poisoned { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Q22/Polymorphism/IEnemy.cs: -------------------------------------------------------------------------------- 1 | namespace Polymorphism 2 | { 3 | interface IEnemy 4 | { 5 | int Health { get; set; } 6 | bool Poisoned { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Q22/Polymorphism/IWeapon.cs: -------------------------------------------------------------------------------- 1 | namespace Polymorphism 2 | { 3 | interface IWeapon 4 | { 5 | int Damage { get; set; } 6 | void Attack(IEnemy enemy); 7 | void Repair(); 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Q22/Polymorphism/Player.cs: -------------------------------------------------------------------------------- 1 | namespace Polymorphism 2 | { 3 | class Player 4 | { 5 | public IWeapon Weapon { get; set; } 6 | 7 | public void Attack(IEnemy enemy) 8 | { 9 | Weapon?.Attack(enemy); 10 | } 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Q22/Polymorphism/PoisonedSword.cs: -------------------------------------------------------------------------------- 1 | namespace Polymorphism 2 | { 3 | class PoisonedSword : Sword 4 | { 5 | public override void Attack(IEnemy enemy) 6 | { 7 | if (Durability > 0) 8 | { 9 | enemy.Poisoned = true; 10 | } 11 | base.Attack(enemy); 12 | } 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Q22/Polymorphism/Polymorphism.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q22/Polymorphism/Program.cs: -------------------------------------------------------------------------------- 1 | namespace Polymorphism 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | var enemy = new Enemy(); 8 | 9 | PoisonedSword poisonedSword = new PoisonedSword(); 10 | poisonedSword.Attack(enemy); // will execute PoisonedSword.Attack 11 | 12 | Sword sword = poisonedSword; 13 | sword.Attack(enemy); // will still execute PoisonedSword.Attack 14 | 15 | IWeapon weapon = poisonedSword; 16 | weapon.Attack(enemy); // will still execute PoisonedSword.Attack 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Q22/Polymorphism/Sword.cs: -------------------------------------------------------------------------------- 1 | namespace Polymorphism 2 | { 3 | class Sword : IWeapon 4 | { 5 | public int Damage { get; set; } 6 | public int Durability { get; set; } 7 | 8 | public virtual void Attack(IEnemy enemy) 9 | { 10 | if (Durability > 0) 11 | { 12 | enemy.Health -= Damage; 13 | Durability--; 14 | } 15 | } 16 | 17 | public void Repair() 18 | { 19 | Durability += 100; 20 | } 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Q22/Q22.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Polymorphism", "Polymorphism\Polymorphism.csproj", "{9D785D1A-D87B-4C07-B25C-ED2D56683050}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {9D785D1A-D87B-4C07-B25C-ED2D56683050}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {9D785D1A-D87B-4C07-B25C-ED2D56683050}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {9D785D1A-D87B-4C07-B25C-ED2D56683050}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {9D785D1A-D87B-4C07-B25C-ED2D56683050}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {BA42102C-31FB-4D5F-A91D-FD6F93213432} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q23/AccessibilityLevels/AccessibilityLevels.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q23/AccessibilityLevels/ExternallyVisibleType.cs: -------------------------------------------------------------------------------- 1 | namespace AccessibilityLevels 2 | { 3 | public class ExternallyVisibleType 4 | { 5 | // visible in other assemblies 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Q23/AccessibilityLevels/HiddenType.cs: -------------------------------------------------------------------------------- 1 | namespace AccessibilityLevels 2 | { 3 | internal class HiddenType 4 | { 5 | // visible only in its own assembly 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Q23/AccessibilityLevels/InternalsVisibleTo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | // can be placed in any file compiled into the assembly 4 | [assembly: InternalsVisibleTo("TestAssembly")] 5 | -------------------------------------------------------------------------------- /Q23/AccessibilityLevels/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AccessibilityLevels 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Q23/AccessibilityLevels/SampleEnum.cs: -------------------------------------------------------------------------------- 1 | namespace AccessibilityLevels 2 | { 3 | public enum SampleEnum 4 | { 5 | // all members are public 6 | PublicValue, 7 | AnotherPublicValue 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Q23/AccessibilityLevels/SampleInterface.cs: -------------------------------------------------------------------------------- 1 | namespace AccessibilityLevels 2 | { 3 | public interface SampleInterface 4 | { 5 | // all members are public 6 | void PublicMember(); 7 | void AnotherPublicMember(); 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Q23/AccessibilityLevels/SampleType.cs: -------------------------------------------------------------------------------- 1 | namespace AccessibilityLevels 2 | { 3 | public class SampleType 4 | { 5 | private void ClassSpecificMethod() 6 | { 7 | // visible only inside the SampleType class 8 | } 9 | 10 | protected void MethodForDerivedClasses() 11 | { 12 | // visible inside the SampleType class and any class deriving from it 13 | } 14 | 15 | internal void AssemblySpecificMethod() 16 | { 17 | // visible in its own assembly only 18 | } 19 | 20 | public void FullyVisibleMethod() 21 | { 22 | // visible everywhere 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Q23/TestAssembly/Program.cs: -------------------------------------------------------------------------------- 1 | using AccessibilityLevels; 2 | 3 | namespace TestAssembly 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | var hidden = new HiddenType(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Q23/TestAssembly/TestAssembly.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Q24/AbstractClasses/AbstractClasses.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q24/AbstractClasses/ISampleInterface.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AbstractClasses 4 | { 5 | interface ISampleInterface 6 | { 7 | int Method(int arg); 8 | 9 | int Property { get; set; } 10 | 11 | event EventHandler MethodInvoked; 12 | 13 | string this[int index] { get; set; } 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Q24/AbstractClasses/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AbstractClasses 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Q24/AbstractClasses/SampleAbstractClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace AbstractClasses 5 | { 6 | abstract class SampleAbstractClass : ISampleInterface 7 | { 8 | public abstract int MethodImplementation(int arg); 9 | public int Method(int arg) 10 | { 11 | OnMethodInvoked(); 12 | return MethodImplementation(arg); 13 | } 14 | 15 | public virtual int Property { get; set; } 16 | 17 | public event EventHandler MethodInvoked; 18 | protected virtual void OnMethodInvoked() 19 | { 20 | MethodInvoked?.Invoke(this, new EventArgs()); 21 | } 22 | 23 | protected Dictionary indexerDictionary = new Dictionary(); 24 | public virtual string this[int index] 25 | { 26 | get 27 | { 28 | return indexerDictionary[index]; 29 | } 30 | set 31 | { 32 | indexerDictionary[index] = value; 33 | } 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Q24/AbstractClasses/SampleClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace AbstractClasses 5 | { 6 | class SampleClass : ISampleInterface 7 | { 8 | public int Method(int arg) 9 | { 10 | OnMethodInvoked(); 11 | return arg * 2; 12 | } 13 | 14 | public int Property { get; set; } 15 | 16 | public event EventHandler MethodInvoked; 17 | 18 | private void OnMethodInvoked() 19 | { 20 | MethodInvoked?.Invoke(this, new EventArgs()); 21 | } 22 | 23 | private Dictionary indexerDictionary = new Dictionary(); 24 | public string this[int index] 25 | { 26 | get 27 | { 28 | return indexerDictionary[index]; 29 | } 30 | set 31 | { 32 | indexerDictionary[index] = value; 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Q24/AbstractClasses/SampleImplementingClass.cs: -------------------------------------------------------------------------------- 1 | namespace AbstractClasses 2 | { 3 | class SampleImplementingClass : SampleAbstractClass 4 | { 5 | public override int MethodImplementation(int arg) 6 | { 7 | return arg * 2; 8 | } 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Q24/Q24.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractClasses", "AbstractClasses\AbstractClasses.csproj", "{772313D3-BEE5-4D52-98B1-CFE0D0770216}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {772313D3-BEE5-4D52-98B1-CFE0D0770216}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {772313D3-BEE5-4D52-98B1-CFE0D0770216}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {772313D3-BEE5-4D52-98B1-CFE0D0770216}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {772313D3-BEE5-4D52-98B1-CFE0D0770216}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {E4E54543-2BA3-4890-9DC6-0DB8CD8E02DF} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q25/ExplicitlyImplementedInterface/ClassMemberAndExplicitImplementation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ExplicitlyImplementedInterface 4 | { 5 | public class ClassMemberAndExplicitImplementation : ISimpleInterface 6 | { 7 | public void Method() 8 | { 9 | Console.WriteLine("Regular class member"); 10 | } 11 | 12 | void ISimpleInterface.Method() 13 | { 14 | Console.WriteLine("Explicit implementation"); 15 | } 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Q25/ExplicitlyImplementedInterface/ExplicitImplementation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ExplicitlyImplementedInterface 4 | { 5 | public class ExplicitImplementation : ISimpleInterface 6 | { 7 | void ISimpleInterface.Method() 8 | { 9 | Console.WriteLine("Explicit implementation"); 10 | } 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Q25/ExplicitlyImplementedInterface/ExplicitTwoInterfaces.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ExplicitlyImplementedInterface 6 | { 7 | public class ExplicitTwoInterfaces : ISimpleInterface, ISecondInterface 8 | { 9 | void ISimpleInterface.Method() 10 | { 11 | Console.WriteLine("ISimpleInterface"); 12 | } 13 | 14 | void ISecondInterface.Method() 15 | { 16 | Console.WriteLine("ISecondInterface"); 17 | } 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Q25/ExplicitlyImplementedInterface/ExplicitlyImplementedInterface.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q25/ExplicitlyImplementedInterface/ISecondInterface.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ExplicitlyImplementedInterface 6 | { 7 | public interface ISecondInterface 8 | { 9 | void Method(); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Q25/ExplicitlyImplementedInterface/ISimpleInterface.cs: -------------------------------------------------------------------------------- 1 | namespace ExplicitlyImplementedInterface 2 | { 3 | public interface ISimpleInterface 4 | { 5 | void Method(); 6 | } 7 | 8 | } 9 | -------------------------------------------------------------------------------- /Q25/ExplicitlyImplementedInterface/ImplicitImplementation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ExplicitlyImplementedInterface 4 | { 5 | public class ImplicitImplementation : ISimpleInterface 6 | { 7 | public void Method() 8 | { 9 | Console.WriteLine("Implicit implementation"); 10 | } 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Q25/ExplicitlyImplementedInterface/ImplicitTwoInterfaces.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ExplicitlyImplementedInterface 4 | { 5 | public class ImplicitTwoInterfaces : ISimpleInterface, ISecondInterface 6 | { 7 | public void Method() 8 | { 9 | Console.WriteLine("Implicit implementation"); 10 | } 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Q26/NewModifier/BaseClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NewModifier 4 | { 5 | public class BaseClass 6 | { 7 | public virtual void Method() 8 | { 9 | Console.WriteLine("From BaseClass"); 10 | } 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Q26/NewModifier/DerivedClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NewModifier 4 | { 5 | public class DerivedClass : BaseClass 6 | { 7 | public override void Method() 8 | { 9 | Console.WriteLine("From DerivedClass"); 10 | } 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Q26/NewModifier/NewModifier.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q26/NewModifier/NewModifierClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NewModifier 4 | { 5 | public class NewModifierClass : BaseClass 6 | { 7 | public new void Method() 8 | { 9 | Console.WriteLine("From NewModifierClass"); 10 | } 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Q26/NewModifier/NonVIrtualBaseClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NewModifier 4 | { 5 | public class NonVirtualBaseClass 6 | { 7 | public void Method() 8 | { 9 | Console.WriteLine("From NonVirtualBaseClass"); 10 | } 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Q26/NewModifier/NonVirtualDerivedClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NewModifier 4 | { 5 | public class NonVirtualDerivedClass : NonVirtualBaseClass 6 | { 7 | public new void Method() // will still compile 8 | { 9 | Console.WriteLine("From NonVirtualDerivedClass"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Q26/Q26.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewModifier", "NewModifier\NewModifier.csproj", "{BFBEB9DE-8165-4365-8FCB-DDA86E037FA0}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {BFBEB9DE-8165-4365-8FCB-DDA86E037FA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {BFBEB9DE-8165-4365-8FCB-DDA86E037FA0}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {BFBEB9DE-8165-4365-8FCB-DDA86E037FA0}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {BFBEB9DE-8165-4365-8FCB-DDA86E037FA0}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {36606246-4F9F-4209-B741-59D233AA7642} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q27/EqualsMethod/CustomEquals/PointClass.cs: -------------------------------------------------------------------------------- 1 | namespace EqualsMethod.CustomEquals 2 | { 3 | public class PointClass 4 | { 5 | public double X { get; set; } 6 | public double Y { get; set; } 7 | 8 | public override bool Equals(object obj) 9 | { 10 | PointClass point = obj as PointClass; 11 | if (point == null) 12 | { 13 | return false; 14 | } 15 | else 16 | { 17 | return X.Equals(point.X) && Y.Equals(point.Y); 18 | } 19 | } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Q27/EqualsMethod/CustomEqualsAndGetHashCode/PointClass.cs: -------------------------------------------------------------------------------- 1 | namespace EqualsMethod.CustomEqualsAndGetHashCode 2 | { 3 | public class PointClass 4 | { 5 | public double X { get; set; } 6 | public double Y { get; set; } 7 | 8 | public override bool Equals(object obj) 9 | { 10 | PointClass point = obj as PointClass; 11 | if (point == null) 12 | { 13 | return false; 14 | } 15 | else 16 | { 17 | return X.Equals(point.X) && Y.Equals(point.Y); 18 | } 19 | } 20 | 21 | //public override int GetHashCode() 22 | //{ 23 | // return X.GetHashCode() ^ Y.GetHashCode(); 24 | //} 25 | 26 | //public override int GetHashCode() 27 | //{ 28 | // unchecked 29 | // { 30 | // return 17 + X.GetHashCode() * 23; 31 | // } 32 | //} 33 | 34 | public override int GetHashCode() 35 | { 36 | return (X, Y).GetHashCode(); 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Q27/EqualsMethod/EqualsMethod.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.2 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Q27/EqualsMethod/Equatable/PointClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace EqualsMethod.Equatable 4 | { 5 | public class PointClass : IEquatable 6 | { 7 | public double X { get; set; } 8 | public double Y { get; set; } 9 | 10 | public bool Equals(PointClass other) 11 | { 12 | if (other == null) 13 | { 14 | return false; 15 | } 16 | else 17 | { 18 | return X.Equals(other.X) && Y.Equals(other.Y); 19 | } 20 | } 21 | 22 | public override bool Equals(object obj) 23 | { 24 | PointClass point = obj as PointClass; 25 | return Equals(point); 26 | } 27 | 28 | //public override int GetHashCode() 29 | //{ 30 | // return X.GetHashCode() ^ Y.GetHashCode(); 31 | //} 32 | 33 | public override int GetHashCode() 34 | { 35 | unchecked 36 | { 37 | return 17 + X.GetHashCode() * 23; 38 | } 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Q27/EqualsMethod/NoCustomEquals/PointClass.cs: -------------------------------------------------------------------------------- 1 | namespace EqualsMethod.NoCustomEquals 2 | { 3 | public class PointClass 4 | { 5 | public double X { get; set; } 6 | public double Y { get; set; } 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Q27/EqualsMethod/NoCustomEquals/PointStruct.cs: -------------------------------------------------------------------------------- 1 | namespace EqualsMethod.NoCustomEquals 2 | { 3 | public struct PointStruct 4 | { 5 | public double X { get; set; } 6 | public double Y { get; set; } 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /Q27/Q27.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EqualsMethod", "EqualsMethod\EqualsMethod.csproj", "{E27B27A3-1753-4698-B468-B52526082BBD}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {E27B27A3-1753-4698-B468-B52526082BBD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {E27B27A3-1753-4698-B468-B52526082BBD}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {E27B27A3-1753-4698-B468-B52526082BBD}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {E27B27A3-1753-4698-B468-B52526082BBD}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {95C590DB-E1A2-4390-AB26-AA999476FC66} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q28/OperatorOverloading/OperatorOverloading.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q29/DelegatesAndEvents/DelegatesAndEvents.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q29/DelegatesAndEvents/InstrumentedNotifyingClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DelegatesAndEvents 4 | { 5 | public class InstrumentedNotifyingClass 6 | { 7 | private EventHandler methodInvokedDelegate; 8 | 9 | public event EventHandler MethodInvoked 10 | { 11 | add 12 | { 13 | methodInvokedDelegate += value; 14 | Console.WriteLine("Added event handler."); 15 | } 16 | 17 | remove 18 | { 19 | methodInvokedDelegate -= value; 20 | Console.WriteLine("Removed event handler."); 21 | } 22 | } 23 | 24 | public void Method(int argument) 25 | { 26 | methodInvokedDelegate?.Invoke(this, new MethodEventArgs(argument)); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Q29/DelegatesAndEvents/MethodEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DelegatesAndEvents 4 | { 5 | public class MethodEventArgs : EventArgs 6 | { 7 | public int Argument { get; private set; } 8 | 9 | public MethodEventArgs(int argument) 10 | { 11 | Argument = argument; 12 | } 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Q29/DelegatesAndEvents/NotifyingClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DelegatesAndEvents 4 | { 5 | public class NotifyingClass 6 | { 7 | public event EventHandler MethodInvoked; 8 | 9 | public void Method(int argument) 10 | { 11 | MethodInvoked?.Invoke(this, new MethodEventArgs(argument)); 12 | } 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Q30/IDisposableInterface/DisposableClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace IDisposableInterface 5 | { 6 | public class DisposableClass : IDisposable 7 | { 8 | bool disposed = false; 9 | private StreamReader reader; 10 | 11 | public DisposableClass(string filename) 12 | { 13 | reader = new StreamReader(filename); 14 | } 15 | 16 | public string Read() 17 | { 18 | if (disposed) 19 | { 20 | throw new ObjectDisposedException(nameof(DisposableClass)); 21 | } 22 | return reader.ReadToEnd(); 23 | } 24 | 25 | public void Dispose() 26 | { 27 | Dispose(true); 28 | GC.SuppressFinalize(this); 29 | } 30 | 31 | protected virtual void Dispose(bool disposing) 32 | { 33 | if (disposing) 34 | { 35 | if (reader != null) 36 | { 37 | reader.Dispose(); 38 | reader = null; 39 | } 40 | } 41 | disposed = true; 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Q30/IDisposableInterface/IDisposableInterface.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | 10 | Always 11 | 12 | 13 | Always 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Q30/IDisposableInterface/TextFile1.txt: -------------------------------------------------------------------------------- 1 | Text -------------------------------------------------------------------------------- /Q30/IDisposableInterface/TextFile2.txt: -------------------------------------------------------------------------------- 1 | Text -------------------------------------------------------------------------------- /Q31/Finalizers/ClassWithFinalizer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Finalizers 5 | { 6 | public class ClassWithFinalizer : IDisposable 7 | { 8 | bool disposed = false; 9 | IntPtr unsafeHandle; 10 | 11 | public ClassWithFinalizer(int size) 12 | { 13 | unsafeHandle = Marshal.AllocHGlobal(size); 14 | } 15 | 16 | ~ClassWithFinalizer() 17 | { 18 | Dispose(false); 19 | } 20 | 21 | public void Dispose() 22 | { 23 | Dispose(true); 24 | GC.SuppressFinalize(this); 25 | } 26 | 27 | protected virtual void Dispose(bool disposing) 28 | { 29 | if (disposing) 30 | { 31 | // dispose nested disposable instances 32 | } 33 | if (unsafeHandle != IntPtr.Zero) 34 | { 35 | Marshal.FreeHGlobal(unsafeHandle); 36 | unsafeHandle = IntPtr.Zero; 37 | } 38 | disposed = true; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Q31/Finalizers/Finalizers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q31/Finalizers/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Finalizers 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Q31/Q31.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Finalizers", "Finalizers\Finalizers.csproj", "{FF92DB01-783A-4D3A-B9DA-614A2D5ED442}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {FF92DB01-783A-4D3A-B9DA-614A2D5ED442}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {FF92DB01-783A-4D3A-B9DA-614A2D5ED442}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {FF92DB01-783A-4D3A-B9DA-614A2D5ED442}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {FF92DB01-783A-4D3A-B9DA-614A2D5ED442}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {5A23A79A-315F-477B-8EB4-442EC9FC0037} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q31/README.md: -------------------------------------------------------------------------------- 1 | The `ClassWithSafeHandle` class in this example only works as expected on Windows because it makes a native library call. -------------------------------------------------------------------------------- /Q32/Q32.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StaticMembers", "StaticMembers\StaticMembers.csproj", "{4D7FC28F-295C-4C93-BC87-D1AA678D33FE}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {4D7FC28F-295C-4C93-BC87-D1AA678D33FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {4D7FC28F-295C-4C93-BC87-D1AA678D33FE}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {4D7FC28F-295C-4C93-BC87-D1AA678D33FE}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {4D7FC28F-295C-4C93-BC87-D1AA678D33FE}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {33C2A4FC-B9D6-44D5-B3EB-A95BDE90F5FE} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q32/StaticMembers/ClassNamespace/FibonacciNumberCalculator.cs: -------------------------------------------------------------------------------- 1 | namespace ClassNamespace 2 | { 3 | internal class FibonacciNumberCalculator 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /Q32/StaticMembers/ClassWithInstanceMembers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace StaticMembers 4 | { 5 | public class ClassWithInstanceMembers 6 | { 7 | public int InstanceProperty { get; set; } 8 | 9 | public void InstanceMethod() 10 | { 11 | Console.WriteLine($"Property value: {InstanceProperty}"); 12 | } 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Q32/StaticMembers/Config.cs: -------------------------------------------------------------------------------- 1 | namespace StaticMembers 2 | { 3 | public static class Config 4 | { 5 | public static bool ThrowException { get; set; } = true; 6 | } 7 | 8 | } 9 | -------------------------------------------------------------------------------- /Q32/StaticMembers/FailingClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace StaticMembers 4 | { 5 | public class FailingClass 6 | { 7 | static FailingClass() 8 | { 9 | if (Config.ThrowException) 10 | { 11 | throw new InvalidOperationException(); 12 | } 13 | } 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Q32/StaticMembers/GenericClass.cs: -------------------------------------------------------------------------------- 1 | namespace StaticMembers 2 | { 3 | class GenericClass 4 | { 5 | public static T StaticProperty { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Q32/StaticMembers/StaticMembers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q33/ExtensionMethods/ExtensionMethods.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q33/ExtensionMethods/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ExtensionMethods 4 | { 5 | public static class StringExtensions 6 | { 7 | public static bool ContainsIgnoreCase(this string instance, string substring) 8 | { 9 | return instance.IndexOf(substring, StringComparison.OrdinalIgnoreCase) >= 0; 10 | } 11 | 12 | public static bool Contains(this string instance, string substring) 13 | { 14 | // use case insensitive comparison instead of case sensitive 15 | return instance.IndexOf(substring, StringComparison.OrdinalIgnoreCase) >= 0; 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Q34/AutoImplementedProperties/AutoImplementedProperties.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q34/AutoImplementedProperties/DerivedClass.cs: -------------------------------------------------------------------------------- 1 | namespace AutoImplementedProperties 2 | { 3 | public class DerivedClass : SampleClass 4 | { 5 | public DerivedClass() 6 | { 7 | RegularProperty = -1; // will throw exception 8 | } 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Q34/AutoImplementedProperties/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AutoImplementedProperties 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | FieldAccess(); 10 | PropertyAccess(); 11 | } 12 | 13 | private static void FieldAccess() 14 | { 15 | var instance = new SampleClass(); 16 | var value = instance.publicField; 17 | instance.publicField = -1; 18 | } 19 | 20 | private static void PropertyAccess() 21 | { 22 | var instance = new SampleClass(); 23 | var value = instance.RegularProperty; 24 | //instance.RegularProperty = -1; // won't compile 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Q35/ExpressionBodiedMembers/ExpressionBodiedMembers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q35/ExpressionBodiedMembers/ExpressionBody/Student.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ExpressionBodiedMembers.ExpressionBody 5 | { 6 | class Student 7 | { 8 | public string Name { get; set; } 9 | public string Surname { get; set; } 10 | 11 | public void Dispose(Boolean dispose) 12 | { } 13 | 14 | public override string ToString() => $"{FullName}, {Age}"; 15 | 16 | public string FullName => $"{Name} {Surname}"; 17 | 18 | private int age; 19 | public int Age 20 | { 21 | get => age; 22 | set => age = value > 0 ? value : throw new ArgumentOutOfRangeException(nameof(value)); 23 | } 24 | 25 | private Dictionary grades = new Dictionary(); 26 | public int? this[string course] 27 | { 28 | get => grades.ContainsKey(course) ? grades[course] : null; 29 | set => grades[course] = value; 30 | } 31 | 32 | public Student(string name, string surname, int age) => (Name, Surname, Age) = (name, surname, age); 33 | 34 | ~Student() => Dispose(false); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Q35/ExpressionBodiedMembers/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ExpressionBodiedMembers 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Q36/InterpolatedStrings/EFContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | 3 | namespace InterpolatedStrings 4 | { 5 | class EFContext : DbContext 6 | { 7 | public DbSet Persons { get; set; } 8 | 9 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => 10 | optionsBuilder.UseSqlite("database.db"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Q36/InterpolatedStrings/InterpolatedStrings.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Q36/InterpolatedStrings/Person.cs: -------------------------------------------------------------------------------- 1 | namespace InterpolatedStrings 2 | { 3 | class Person 4 | { 5 | public int Id { get; set; } 6 | public string FirstName { get; set; } 7 | public string LastName { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Q36/InterpolatedStrings/Properties/Strings.cs: -------------------------------------------------------------------------------- 1 | namespace InterpolatedStrings.Properties 2 | { 3 | class Strings 4 | { 5 | public static string Localized { get; } = "Hello, {0}!"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Q37/LocaleStringManipulation/LocaleStringManipulation.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q38/StringManipulation/StringManipulation.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q39/GenericCodeImprovements/GenericCodeImprovements.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q40/ImplementGenerics/GenericComparer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace ImplementGenerics 5 | { 6 | public class GenericComparer 7 | { 8 | private readonly T compareWith; 9 | 10 | public GenericComparer(T compareWith) 11 | { 12 | this.compareWith = compareWith; 13 | } 14 | 15 | public int CountDifferent(IEnumerable vals) 16 | { 17 | return vals.Count(val => !object.Equals(val, compareWith)); 18 | } 19 | 20 | public int CountEqual(IEnumerable numbers) 21 | { 22 | return numbers.Count(val => object.Equals(val, compareWith)); 23 | } 24 | } 25 | 26 | public static class GenericComparer 27 | { 28 | public static GenericComparer Create(T compareWith) 29 | { 30 | return new GenericComparer(compareWith); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Q40/ImplementGenerics/ImplementGenerics.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q40/ImplementGenerics/IntComparer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace ImplementGenerics 5 | { 6 | public class IntComparer 7 | { 8 | private readonly int compareWith; 9 | 10 | public IntComparer(int compareWith) 11 | { 12 | this.compareWith = compareWith; 13 | } 14 | 15 | public int CountDifferent(IEnumerable numbers) 16 | { 17 | return numbers.Count(number => number != compareWith); 18 | } 19 | 20 | public int CountEqual(IEnumerable numbers) 21 | { 22 | return numbers.Count(number => number == compareWith); 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Q41/GenericTypeConstraints/Extensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | 4 | namespace GenericTypeConstraints 5 | { 6 | static class Extensions 7 | { 8 | public static bool IsAfter(this T value, T compareTo) where T : IComparable 9 | { 10 | return value.CompareTo(compareTo) > 0; 11 | } 12 | 13 | public static TDelegate Combine(this TDelegate source, TDelegate target) where TDelegate : Delegate 14 | { 15 | // Delegate.Combine must be used instead of the + operator 16 | return (TDelegate)Delegate.Combine(source, target); 17 | } 18 | 19 | public static string GetDescription(this TEnum value) where TEnum : Enum 20 | { 21 | var type = typeof(TEnum); 22 | var member = type.GetMember(value.ToString()); 23 | var attribute = (DescriptionAttribute)Attribute.GetCustomAttribute(member[0], typeof(DescriptionAttribute)); 24 | return attribute != null ? attribute.Description : value.ToString(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Q41/GenericTypeConstraints/FuelType.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace GenericTypeConstraints 4 | { 5 | public enum FuelType 6 | { 7 | Petrol, 8 | Diesel, 9 | [Description("Liquid petroleum gas")] 10 | LPG 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Q41/GenericTypeConstraints/GenericTypeConstraints.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7.3 7 | 8 | 9 | 10 | true 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Q41/GenericTypeConstraints/IPerson.cs: -------------------------------------------------------------------------------- 1 | namespace GenericTypeConstraints 2 | { 3 | public interface IPerson 4 | { 5 | string FirstName { get; set; } 6 | string LastName { get; set; } 7 | int Age { get; set; } 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Q41/GenericTypeConstraints/Member.cs: -------------------------------------------------------------------------------- 1 | namespace GenericTypeConstraints 2 | { 3 | class Member : IPerson 4 | { 5 | public string FirstName { get; set; } 6 | public string LastName { get; set; } 7 | public int Age { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Q41/GenericTypeConstraints/PersonClass.cs: -------------------------------------------------------------------------------- 1 | namespace GenericTypeConstraints 2 | { 3 | class PersonClass : IPerson 4 | { 5 | public string FirstName { get; set; } 6 | public string LastName { get; set; } 7 | public int Age { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Q41/GenericTypeConstraints/PersonStruct.cs: -------------------------------------------------------------------------------- 1 | namespace GenericTypeConstraints 2 | { 3 | struct PersonStruct : IPerson 4 | { 5 | public string FirstName { get; set; } 6 | public string LastName { get; set; } 7 | public int Age { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Q42/CovarianceContravariance/CovarianceContravariance.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q42/CovarianceContravariance/IVariant.cs: -------------------------------------------------------------------------------- 1 | namespace CovarianceContravariance 2 | { 3 | public interface IVariant 4 | { 5 | TCovariant Covariant(); 6 | void Contravariant(TContravariant input); 7 | TInvariant Invariant(TInvariant input); 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Q42/CovarianceContravariance/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace CovarianceContravariance 5 | { 6 | class Program 7 | { 8 | public delegate TCovariant VariantDelegate(TContravariant input); 9 | 10 | static void Main(string[] args) 11 | { 12 | IList list = new List(); 13 | //IList lessDerivedList = list; // won't compile 14 | 15 | IEnumerable strings = new List(); 16 | IEnumerable objects = strings; 17 | 18 | Predicate objectPredicate = obj => obj.ToString().Length > 5; 19 | Predicate stringPredicate = objectPredicate; 20 | 21 | Func originalDelegate = obj => obj.ToString(); 22 | Func variantDelegate = originalDelegate; 23 | 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Q43/IEnumerableInterface/IEnumerableInterface.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q43/IEnumerableInterface/NoIEnumerable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace IEnumerableInterface 4 | { 5 | public class NoIEnumerable 6 | { 7 | private readonly IEnumerable enumerable; 8 | 9 | public NoIEnumerable(IEnumerable enumerable) 10 | { 11 | this.enumerable = enumerable; 12 | } 13 | 14 | public IEnumerator GetEnumerator() => enumerable.GetEnumerator(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Q44/ImplementIEnumerable/ImplementIEnumerable.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q45/ArraysAndCollections/ArraysAndCollections.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q46/CollectionClasses/CollectionClasses.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q47/ConcurrentCollections/ConcurrentCollections.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q47/ConcurrentCollections/DictionaryWithLock.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ConcurrentCollections 4 | { 5 | public class DictionaryWithLock 6 | { 7 | private readonly object syncObject; 8 | private readonly Dictionary dictionary; 9 | 10 | public DictionaryWithLock() 11 | { 12 | syncObject = new object(); 13 | dictionary = new Dictionary(); 14 | } 15 | 16 | public TValue this[TKey key] 17 | { 18 | get 19 | { 20 | lock (syncObject) 21 | { 22 | return dictionary[key]; 23 | } 24 | } 25 | set 26 | { 27 | lock (syncObject) 28 | { 29 | dictionary[key] = value; 30 | } 31 | } 32 | } 33 | 34 | public void Add(TKey key, TValue value) 35 | { 36 | lock (syncObject) 37 | { 38 | dictionary.Add(key, value); 39 | } 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Q47/ConcurrentCollections/ExpensiveResource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ConcurrentCollections 6 | { 7 | public class ExpensiveResource 8 | { 9 | private ExpensiveResource() 10 | { } 11 | 12 | public static ExpensiveResource Create(string key) 13 | { 14 | return new ExpensiveResource(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Q47/ConcurrentCollections/Program.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | 3 | namespace ConcurrentCollections 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | var concurrentDictionary = new ConcurrentDictionary(); 10 | var newKey = "key"; 11 | 12 | var resource = concurrentDictionary.GetOrAdd(newKey, key => ExpensiveResource.Create(key)); 13 | 14 | 15 | var syncObject = new object(); 16 | 17 | var success = concurrentDictionary.TryGetValue(newKey, out resource); 18 | if (!success) 19 | { 20 | lock (syncObject) 21 | { 22 | // was the resource created by another thread after the check outside of lock? 23 | if (!concurrentDictionary.TryGetValue(newKey, out resource)) 24 | { 25 | resource = ExpensiveResource.Create(newKey); 26 | concurrentDictionary.TryAdd(newKey, resource); 27 | } 28 | } 29 | } 30 | 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Q48/ImmutableCollections/ImmutableCollections.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Q49/LinqStructure/LinqStructure.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q49/LinqStructure/Person.cs: -------------------------------------------------------------------------------- 1 | namespace LinqStructure 2 | { 3 | public class Person 4 | { 5 | public string FirstName { get; set; } 6 | public string LastName { get; set; } 7 | public int Age { get; set; } 8 | 9 | public Person(string firstName, string lastName, int age) 10 | { 11 | FirstName = firstName; 12 | LastName = lastName; 13 | Age = age; 14 | } 15 | 16 | public override string ToString() 17 | { 18 | return $"FirstName: {FirstName}, LastName: {LastName}, Age: {Age}"; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Q49/Q49.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinqStructure", "LinqStructure\LinqStructure.csproj", "{B8B9423B-0FED-4812-B854-16ECEA3B0F6C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {B8B9423B-0FED-4812-B854-16ECEA3B0F6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {B8B9423B-0FED-4812-B854-16ECEA3B0F6C}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {B8B9423B-0FED-4812-B854-16ECEA3B0F6C}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {B8B9423B-0FED-4812-B854-16ECEA3B0F6C}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {DDC7D397-C54F-4F38-BD6B-157FCBE6A210} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q50/LinqMethodSyntax/LinqMethodSyntax.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q50/LinqMethodSyntax/Person.cs: -------------------------------------------------------------------------------- 1 | namespace LinqMethodSyntax 2 | { 3 | public class Person 4 | { 5 | public string FirstName { get; set; } 6 | public string LastName { get; set; } 7 | public int Age { get; set; } 8 | 9 | public Person(string firstName, string lastName, int age) 10 | { 11 | FirstName = firstName; 12 | LastName = lastName; 13 | Age = age; 14 | } 15 | 16 | public override string ToString() 17 | { 18 | return $"FirstName: {FirstName}, LastName: {LastName}, Age: {Age}"; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Q50/LinqMethodSyntax/Room.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LinqMethodSyntax 6 | { 7 | public class Room 8 | { 9 | public int Number { get; set; } 10 | public Person[] Guests { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Q51/LinqJoins/LinqJoins.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q51/LinqJoins/Registration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LinqJoins 4 | { 5 | class Registration 6 | { 7 | public int StudentId { get; set; } 8 | public int CourseId { get; set; } 9 | public DateTime DateRegistered { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Q51/LinqJoins/Student.cs: -------------------------------------------------------------------------------- 1 | namespace LinqJoins 2 | { 3 | class Student 4 | { 5 | public int Id { get; set; } 6 | public string FirstName { get; set; } 7 | public string LastName { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Q51/LinqJoins/StudentGrade.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LinqJoins 4 | { 5 | class StudentGrade 6 | { 7 | public int StudentId { get; set; } 8 | public int CourseId { get; set; } 9 | public DateTime GradingDate { get; set; } 10 | public int Grade { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Q51/Q51.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinqJoins", "LinqJoins\LinqJoins.csproj", "{C8E08CF4-2095-453D-8D5F-9BA8407B84D3}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C8E08CF4-2095-453D-8D5F-9BA8407B84D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {C8E08CF4-2095-453D-8D5F-9BA8407B84D3}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {C8E08CF4-2095-453D-8D5F-9BA8407B84D3}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {C8E08CF4-2095-453D-8D5F-9BA8407B84D3}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {02CED404-ED48-4F48-8EE9-E5D1622429F8} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q52/LinqSetOperations/LinqSetOperations.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q52/LinqSetOperations/Person.cs: -------------------------------------------------------------------------------- 1 | namespace LinqSetOperations 2 | { 3 | public class Person 4 | { 5 | public int Id { get; set; } 6 | public string FirstName { get; set; } 7 | public string LastName { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Q52/LinqSetOperations/PersonComparer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace LinqSetOperations 4 | { 5 | public class PersonComparer : IEqualityComparer 6 | { 7 | public bool Equals(Person x, Person y) 8 | { 9 | return x.Id == y.Id; 10 | } 11 | 12 | public int GetHashCode(Person obj) 13 | { 14 | return obj.Id.GetHashCode(); 15 | } 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /Q53/LinqAggregation/LinqAggregation.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7.2 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Q53/LinqAggregation/Person.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace LinqAggregation 6 | { 7 | class Person 8 | { 9 | public string FirstName { get; set; } 10 | public string LastName { get; set; } 11 | public int Age { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Q53/Q53.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinqAggregation", "LinqAggregation\LinqAggregation.csproj", "{8F8C6B27-9BD0-420B-B8CA-C48C649FDD62}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {8F8C6B27-9BD0-420B-B8CA-C48C649FDD62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {8F8C6B27-9BD0-420B-B8CA-C48C649FDD62}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {8F8C6B27-9BD0-420B-B8CA-C48C649FDD62}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {8F8C6B27-9BD0-420B-B8CA-C48C649FDD62}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {E0D294A3-D559-4DB9-B0CC-07072C8273E0} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q54/LinqGrouping/LinqGrouping.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q54/Q54.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinqGrouping", "LinqGrouping\LinqGrouping.csproj", "{692E44F2-12B0-4090-A984-80FA011C4680}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {692E44F2-12B0-4090-A984-80FA011C4680}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {692E44F2-12B0-4090-A984-80FA011C4680}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {692E44F2-12B0-4090-A984-80FA011C4680}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {692E44F2-12B0-4090-A984-80FA011C4680}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {4058056E-B5B8-4C45-92B1-CEF937C55F52} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q55/LinqDeferredExecution/LinqDeferredExecution.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q56/LinqQueryExecution/Extensions/EnumerableExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace LinqQueryExecution.Extensions 5 | { 6 | static class EnumerableExtensions 7 | { 8 | public static IEnumerable Where(this IEnumerable list, Func predicate) 9 | { 10 | foreach (var item in list) 11 | { 12 | if (predicate(item)) 13 | { 14 | yield return item; 15 | } 16 | } 17 | } 18 | 19 | public static int Sum(this IEnumerable list) 20 | { 21 | var sum = 0; 22 | foreach (var item in list) 23 | { 24 | sum += item; 25 | } 26 | return sum; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Q56/LinqQueryExecution/LinqQueryExecution.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | Always 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Q56/LinqQueryExecution/Migrations/20190119102455_InitialCreate.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | namespace LinqQueryExecution.Migrations 4 | { 5 | public partial class InitialCreate : Migration 6 | { 7 | protected override void Up(MigrationBuilder migrationBuilder) 8 | { 9 | migrationBuilder.CreateTable( 10 | name: "Persons", 11 | columns: table => new 12 | { 13 | Id = table.Column(nullable: false) 14 | .Annotation("Sqlite:Autoincrement", true), 15 | Name = table.Column(nullable: true), 16 | Surname = table.Column(nullable: true), 17 | Age = table.Column(nullable: false) 18 | }, 19 | constraints: table => 20 | { 21 | table.PrimaryKey("PK_Persons", x => x.Id); 22 | }); 23 | } 24 | 25 | protected override void Down(MigrationBuilder migrationBuilder) 26 | { 27 | migrationBuilder.DropTable( 28 | name: "Persons"); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Q56/LinqQueryExecution/Person.cs: -------------------------------------------------------------------------------- 1 | namespace LinqQueryExecution 2 | { 3 | public class Person 4 | { 5 | public int Id { get; set; } 6 | public string Name { get; set; } 7 | public string Surname { get; set; } 8 | public int Age { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Q56/LinqQueryExecution/PersonContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | 3 | namespace LinqQueryExecution 4 | { 5 | public class PersonContext : DbContext 6 | { 7 | public PersonContext() { } 8 | 9 | public PersonContext(DbContextOptions options) 10 | : base(options) 11 | { } 12 | 13 | // maps to the Persons table in database 14 | public DbSet Persons { get; set; } 15 | 16 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 17 | { 18 | optionsBuilder.UseSqlite("Data Source = Persons.db"); 19 | } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Q56/LinqQueryExecution/Persons.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnetcurry/csharpbook/7eb18e67855e9e74db865027328438365ffe5eae/Q56/LinqQueryExecution/Persons.db -------------------------------------------------------------------------------- /Q56/LinqQueryExecution/Program.CustomExtensions.cs: -------------------------------------------------------------------------------- 1 | using LinqQueryExecution.Extensions; 2 | using System.Collections.Generic; 3 | 4 | namespace LinqQueryExecution 5 | { 6 | partial class Program 7 | { 8 | private static void WhereExtension() 9 | { 10 | var list = new List { 1, 2, 3, 4, 5 }; 11 | var query = list.Where(item => item < 3); // not executed yet 12 | } 13 | 14 | private static void SumExtension() 15 | { 16 | var list = new List { 1, 2, 3, 4, 5 }; 17 | var sum = list.Sum(); // executes immediately 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Q57/LinqQueryExecution/LinqQueryExecution.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Q57/LinqQueryExecution/Person.cs: -------------------------------------------------------------------------------- 1 | namespace LinqQueryExecution 2 | { 3 | public class Person 4 | { 5 | public int Id { get; set; } 6 | public string Name { get; set; } 7 | public string Surname { get; set; } 8 | public int Age { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Q57/LinqQueryExecution/PersonContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | 3 | namespace LinqQueryExecution 4 | { 5 | class PersonContext : DbContext 6 | { 7 | public PersonContext() { } 8 | 9 | public DbSet Persons { get; set; } 10 | 11 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 12 | { 13 | optionsBuilder.UseSqlite("Data Source = Persons.db"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Q58/QueryableVsEnumerable/Migrations/20190119105807_InitialCreate.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | namespace QueryableVsEnumerable.Migrations 4 | { 5 | public partial class InitialCreate : Migration 6 | { 7 | protected override void Up(MigrationBuilder migrationBuilder) 8 | { 9 | migrationBuilder.CreateTable( 10 | name: "Persons", 11 | columns: table => new 12 | { 13 | Id = table.Column(nullable: false) 14 | .Annotation("Sqlite:Autoincrement", true), 15 | Name = table.Column(nullable: true), 16 | Surname = table.Column(nullable: true), 17 | Age = table.Column(nullable: false) 18 | }, 19 | constraints: table => 20 | { 21 | table.PrimaryKey("PK_Persons", x => x.Id); 22 | }); 23 | } 24 | 25 | protected override void Down(MigrationBuilder migrationBuilder) 26 | { 27 | migrationBuilder.DropTable( 28 | name: "Persons"); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Q58/QueryableVsEnumerable/Person.cs: -------------------------------------------------------------------------------- 1 | namespace QueryableVsEnumerable 2 | { 3 | public class Person 4 | { 5 | public int Id { get; set; } 6 | public string Name { get; set; } 7 | public string Surname { get; set; } 8 | public int Age { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Q58/QueryableVsEnumerable/PersonContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | 3 | namespace QueryableVsEnumerable 4 | { 5 | class PersonContext : DbContext 6 | { 7 | public PersonContext() { } 8 | 9 | public DbSet Persons { get; set; } 10 | 11 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 12 | { 13 | optionsBuilder.UseSqlite("Data Source = Persons.db"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Q58/QueryableVsEnumerable/Persons.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnetcurry/csharpbook/7eb18e67855e9e74db865027328438365ffe5eae/Q58/QueryableVsEnumerable/Persons.db -------------------------------------------------------------------------------- /Q58/QueryableVsEnumerable/QueryableVsEnumerable.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | Always 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Q58/QueryableVsEnumerable/RepositoryExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | 6 | namespace QueryableVsEnumerable 7 | { 8 | static class RepositoryExtensions 9 | { 10 | public static IEnumerable GetPersonsExternalContext(this PersonContext context, Expression> predicate) 11 | { 12 | return context.Persons.Where(predicate); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Q59/ConcurrentMultithreadedAsynchronous/ConcurrentMultithreadedAsynchronous.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | 10 | Always 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Q59/ConcurrentMultithreadedAsynchronous/TextFile1.txt: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /Q60/README.md: -------------------------------------------------------------------------------- 1 | `WindowsFormsTimer` and `WpfTimer` are Windows specific .NET framework projects and require Visual Studio 2017 to run. -------------------------------------------------------------------------------- /Q60/Timers/Program.cs: -------------------------------------------------------------------------------- 1 | namespace Timers 2 | { 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | ThreadingTimer(); 8 | TimersTimer(); 9 | } 10 | 11 | private static void ThreadingTimer() 12 | { 13 | object stateObject = null; 14 | 15 | var timer = new System.Threading.Timer(state => 16 | { 17 | // code to execute 18 | }, stateObject, 50, System.Threading.Timeout.Infinite); 19 | } 20 | 21 | private static void TimersTimer() 22 | { 23 | object stateObject = null; 24 | 25 | var timer = new System.Threading.Timer(state => 26 | { 27 | // code to execute 28 | }, stateObject, 50, System.Threading.Timeout.Infinite); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Q60/Timers/Timers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q60/WindowsFormsTimer/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Q60/WindowsFormsTimer/Form1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace WindowsFormsTimer 5 | { 6 | public partial class Form1 : Form 7 | { 8 | public Form1() 9 | { 10 | InitializeComponent(); 11 | } 12 | 13 | private void timer_Tick(object sender, EventArgs e) 14 | { 15 | // code to execute 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Q60/WindowsFormsTimer/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace WindowsFormsTimer 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new Form1()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Q60/WindowsFormsTimer/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Q60/WpfTimer/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Q60/WpfTimer/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Q60/WpfTimer/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace WpfTimer 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Q60/WpfTimer/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Q60/WpfTimer/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Threading; 4 | 5 | namespace WpfTimer 6 | { 7 | /// 8 | /// Interaction logic for MainWindow.xaml 9 | /// 10 | public partial class MainWindow : Window 11 | { 12 | public MainWindow() 13 | { 14 | InitializeComponent(); 15 | 16 | var timer = new DispatcherTimer(); 17 | timer.IsEnabled = true; 18 | timer.Interval = new TimeSpan(50); 19 | timer.Tick += (source, eventArgs) => 20 | { 21 | // code to execute 22 | }; 23 | 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Q60/WpfTimer/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Q61/AbortingThreads/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Q61/AbortingThreads/Program.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | 3 | namespace AbortingThreads 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | ThreadAbort(); 10 | } 11 | 12 | private static void Abortable() 13 | { 14 | try 15 | { 16 | // do processing 17 | } 18 | catch (ThreadAbortException) 19 | { 20 | // clean up after abort 21 | } 22 | } 23 | 24 | private static void ThreadAbort() 25 | { 26 | var thread = new Thread(Abortable); 27 | thread.Start(); 28 | thread.Abort(); 29 | thread.Join(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Q61/README.md: -------------------------------------------------------------------------------- 1 | Because .NET Core doesn't support `Thread.Abort()`, it is called from a separate `AbortingThreads` Windows specific .NET framework project which requires Visual Studio 2017 to run. -------------------------------------------------------------------------------- /Q61/Threads/Threads.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q62/MultithreadingAbstractions/MultithreadingAbstractions.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q63/TaskBasedAsynchronousModel/TaskBasedAsynchronousModel.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7.1 7 | 8 | 9 | 10 | 11 | Always 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Q63/TaskBasedAsynchronousModel/src.txt: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /Q64/AsynchronousProgrammingModel/AsynchronousProgrammingModel.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7.1 7 | 8 | 9 | 10 | 11 | Always 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Q64/AsynchronousProgrammingModel/TextFile1.txt: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /Q65/EventBasedAsynchronousPattern/EventBasedAsynchronousPattern.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7.1 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Q66/AsyncAwaitCodeExecution/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Q66/AsyncAwaitCodeExecution/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Q66/AsyncAwaitCodeExecution/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace AsyncAwaitCodeExecution 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Q66/AsyncAwaitCodeExecution/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Q66/AsyncAwaitCodeExecution/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Q66/README.md: -------------------------------------------------------------------------------- 1 | This example is Windows specific and requires Visual Studio 2017 to run because `AsyncAwaitCodeExecution` is a .NET framework project. -------------------------------------------------------------------------------- /Q67/AsyncInExistingCode/AsyncInExistingCode.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7.1 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Q67/AsyncInExistingCode/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace AsyncInExistingCode 5 | { 6 | class Program 7 | { 8 | static async Task Main(string[] args) 9 | { 10 | await AsyncMethod(); 11 | SyncMethodWithBlocking(); 12 | SyncMethodFireAndForget(); 13 | } 14 | 15 | private static Task GetDataAsync() 16 | { 17 | return Task.FromResult(new object()); 18 | } 19 | 20 | private static async Task AsyncMethod() 21 | { 22 | var data = await GetDataAsync(); 23 | // ... 24 | } 25 | 26 | public static void SyncMethodWithBlocking() 27 | { 28 | var data = GetDataAsync().Result; 29 | // ... 30 | } 31 | 32 | private static void SyncMethodFireAndForget() 33 | { 34 | GetDataAsync(); 35 | // ... 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Q67/NewConsoleApp/NewConsoleApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7.1 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Q67/NewConsoleApp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace NewConsoleApp 5 | { 6 | class Program 7 | { 8 | private static Task GetDataAsync() 9 | { 10 | return Task.FromResult(new object()); 11 | } 12 | 13 | static async Task Main(string[] args) 14 | { 15 | var data = await GetDataAsync(); 16 | // ... 17 | 18 | var result = 0; 19 | 20 | return result; 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Q67/OldConsoleApp/OldConsoleApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q67/OldConsoleApp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace OldConsoleApp 5 | { 6 | class Program 7 | { 8 | private static Task GetDataAsync() 9 | { 10 | return Task.FromResult(new object()); 11 | } 12 | 13 | static void Main(string[] args) 14 | { 15 | MainAsync(args).GetAwaiter().GetResult(); 16 | } 17 | 18 | static async Task MainAsync(string[] args) 19 | { 20 | var data = await GetDataAsync(); 21 | // ... 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Q67/README.md: -------------------------------------------------------------------------------- 1 | `WpfApp` is a Windows specific .NET framework project and requires Visual Studio 2017 to run. -------------------------------------------------------------------------------- /Q67/WebApplication/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Mvc; 7 | using WebApplication.Models; 8 | 9 | namespace WebApplication.Controllers 10 | { 11 | public class HomeController : Controller 12 | { 13 | private Task GetDataAsync() 14 | { 15 | return Task.FromResult(new object()); 16 | } 17 | 18 | public async Task Index() 19 | { 20 | var data = await GetDataAsync(); 21 | // ... 22 | return View(); 23 | } 24 | 25 | 26 | public IActionResult Privacy() 27 | { 28 | return View(); 29 | } 30 | 31 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] 32 | public IActionResult Error() 33 | { 34 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Q67/WebApplication/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace WebApplication.Models 4 | { 5 | public class ErrorViewModel 6 | { 7 | public string RequestId { get; set; } 8 | 9 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 10 | } 11 | } -------------------------------------------------------------------------------- /Q67/WebApplication/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace WebApplication 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateWebHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Q67/WebApplication/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:35121", 7 | "sslPort": 44393 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "WebApplication": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Q67/WebApplication/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Home Page"; 3 | } 4 | 5 |
6 |

Welcome

7 |

Learn about building Web apps with ASP.NET Core.

8 |
9 | -------------------------------------------------------------------------------- /Q67/WebApplication/Views/Home/Privacy.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Privacy Policy"; 3 | } 4 |

@ViewData["Title"]

5 | 6 |

Use this page to detail your site's privacy policy.

7 | -------------------------------------------------------------------------------- /Q67/WebApplication/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model ErrorViewModel 2 | @{ 3 | ViewData["Title"] = "Error"; 4 | } 5 | 6 |

Error.

7 |

An error occurred while processing your request.

8 | 9 | @if (Model.ShowRequestId) 10 | { 11 |

12 | Request ID: @Model.RequestId 13 |

14 | } 15 | 16 |

Development Mode

17 |

18 | Swapping to Development environment will display more detailed information about the error that occurred. 19 |

20 |

21 | The Development environment shouldn't be enabled for deployed applications. 22 | It can result in displaying sensitive information from exceptions to end users. 23 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 24 | and restarting the app. 25 |

26 | -------------------------------------------------------------------------------- /Q67/WebApplication/Views/Shared/_CookieConsentPartial.cshtml: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Http.Features 2 | 3 | @{ 4 | var consentFeature = Context.Features.Get(); 5 | var showBanner = !consentFeature?.CanTrack ?? false; 6 | var cookieString = consentFeature?.CreateConsentCookie(); 7 | } 8 | 9 | @if (showBanner) 10 | { 11 | 17 | 25 | } 26 | -------------------------------------------------------------------------------- /Q67/WebApplication/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using WebApplication 2 | @using WebApplication.Models 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /Q67/WebApplication/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /Q67/WebApplication/WebApplication.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.2 5 | InProcess 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Q67/WebApplication/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Q67/WebApplication/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning" 5 | } 6 | }, 7 | "AllowedHosts": "*" 8 | } 9 | -------------------------------------------------------------------------------- /Q67/WebApplication/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnetcurry/csharpbook/7eb18e67855e9e74db865027328438365ffe5eae/Q67/WebApplication/wwwroot/favicon.ico -------------------------------------------------------------------------------- /Q67/WebApplication/wwwroot/js/site.js: -------------------------------------------------------------------------------- 1 | // Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2 | // for details on configuring this project to bundle and minify static web assets. 3 | 4 | // Write your JavaScript code. 5 | -------------------------------------------------------------------------------- /Q67/WebApplication/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) .NET Foundation. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | these files except in compliance with the License. You may obtain a copy of the 5 | License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software distributed 10 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 11 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 12 | specific language governing permissions and limitations under the License. 13 | -------------------------------------------------------------------------------- /Q67/WpfApp/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Q67/WpfApp/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Q67/WpfApp/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Threading; 9 | 10 | namespace WpfApp 11 | { 12 | /// 13 | /// Interaction logic for App.xaml 14 | /// 15 | public partial class App : Application 16 | { 17 | public App() 18 | { 19 | DispatcherUnhandledException += App_DispatcherUnhandledException; 20 | } 21 | 22 | private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) 23 | { 24 | var exception = e.Exception; // get exception 25 | // ... show the error to the user 26 | e.Handled = true; // prevent the application from crashing 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Q67/WpfApp/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Q67/WpfApp/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Navigation; 14 | using System.Windows.Shapes; 15 | 16 | namespace WpfApp 17 | { 18 | /// 19 | /// Interaction logic for MainWindow.xaml 20 | /// 21 | public partial class MainWindow : Window 22 | { 23 | private Task GetDataAsync() 24 | { 25 | return Task.FromResult(new object()); 26 | } 27 | 28 | public MainWindow() 29 | { 30 | InitializeComponent(); 31 | } 32 | 33 | private async void Button_Click(object sender, RoutedEventArgs e) 34 | { 35 | var data = await GetDataAsync(); 36 | // ... 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Q67/WpfApp/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Q68/AsyncPitfalls/AsyncPitfalls.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7.1 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Q68/README.md: -------------------------------------------------------------------------------- 1 | `WpfApp` is a Windows specific .NET framework project and requires Visual Studio 2017 to run. -------------------------------------------------------------------------------- /Q68/WpfApp/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Q68/WpfApp/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Q68/WpfApp/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace WpfApp 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Q68/WpfApp/InnocentLookingClass.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace WpfApp 4 | { 5 | public class InnocentLookingClass 6 | { 7 | private readonly bool continueOnCapturedContext; 8 | 9 | public InnocentLookingClass(bool continueOnCapturedContext = true) 10 | { 11 | this.continueOnCapturedContext = continueOnCapturedContext; 12 | 13 | DoSomeLengthyStuffAsync().Wait(); 14 | // do some more stuff 15 | } 16 | 17 | private async Task DoSomeLengthyStuffAsync() 18 | { 19 | await SomeOtherLengthyStuffAsync().ConfigureAwait(continueOnCapturedContext); 20 | } 21 | 22 | // other class members 23 | 24 | private Task SomeOtherLengthyStuffAsync() 25 | { 26 | return Task.Run(() => { }); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Q68/WpfApp/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Q68/WpfApp/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Q69/AsyncExceptions/AsyncExceptions.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7.1 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Q69/Q69.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AsyncExceptions", "AsyncExceptions\AsyncExceptions.csproj", "{AF44EA69-6781-4BC9-AF8C-E87EDA2B66AF}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {AF44EA69-6781-4BC9-AF8C-E87EDA2B66AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {AF44EA69-6781-4BC9-AF8C-E87EDA2B66AF}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {AF44EA69-6781-4BC9-AF8C-E87EDA2B66AF}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {AF44EA69-6781-4BC9-AF8C-E87EDA2B66AF}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {55389A43-CBE9-46B3-9582-2609441C6B5F} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q70/AsyncFileOperations/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Q70/AsyncFileOperations/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Q70/AsyncFileOperations/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace AsyncFileOperations 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Q70/AsyncFileOperations/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Q70/AsyncFileOperations/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Q70/README.md: -------------------------------------------------------------------------------- 1 | This example is Windows specific and requires Visual Studio 2017 to run because `AsyncFileOperations` is a .NET framework project. -------------------------------------------------------------------------------- /Q71/CriticalSection/CriticalSection.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q71/CriticalSection/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CriticalSection 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | var accountA = new BankAccount(100); 10 | var accountB = new BankAccount(100); 11 | 12 | Transfer(50, accountA, accountB); 13 | } 14 | 15 | private static void Transfer(decimal amount, BankAccount from, BankAccount to) 16 | { 17 | lock (to) 18 | { 19 | from.WithdrawPublicLock(amount); 20 | to.Deposit(amount); 21 | } 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Q71/Q71.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CriticalSection", "CriticalSection\CriticalSection.csproj", "{1E5F4226-96E7-46FB-A55E-D282A5EAF4B5}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {1E5F4226-96E7-46FB-A55E-D282A5EAF4B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {1E5F4226-96E7-46FB-A55E-D282A5EAF4B5}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {1E5F4226-96E7-46FB-A55E-D282A5EAF4B5}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {1E5F4226-96E7-46FB-A55E-D282A5EAF4B5}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {3FBCF6B6-4972-40DE-A079-1E930EAF9D19} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q72/ThreadSynchronization/ThreadSynchronization.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q73/Q73.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serialization", "Serialization\Serialization.csproj", "{8A3B2D9A-A3D2-46FE-93D5-0249B3DADA91}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {8A3B2D9A-A3D2-46FE-93D5-0249B3DADA91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {8A3B2D9A-A3D2-46FE-93D5-0249B3DADA91}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {8A3B2D9A-A3D2-46FE-93D5-0249B3DADA91}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {8A3B2D9A-A3D2-46FE-93D5-0249B3DADA91}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {0F4C7E93-EB00-4908-BDCC-3285058389A1} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q73/Serialization/Bow.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace Serialization 4 | { 5 | [DataContract] 6 | public class Bow : IWeapon 7 | { 8 | [DataMember] 9 | public int Damage { get; set; } 10 | [DataMember] 11 | public int Arrows { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Q73/Serialization/Hero.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.Serialization; 4 | using System.Text; 5 | 6 | namespace Serialization 7 | { 8 | [DataContract] 9 | [KnownType(typeof(Bow))] 10 | public class Hero 11 | { 12 | [DataMember] 13 | public IWeapon Weapon { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Q73/Serialization/IWeapon.cs: -------------------------------------------------------------------------------- 1 | namespace Serialization 2 | { 3 | public interface IWeapon 4 | { 5 | int Damage { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Q73/Serialization/Node.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace Serialization 4 | { 5 | [DataContract] 6 | public class Node 7 | { 8 | [DataMember] 9 | public T Value { get; set; } 10 | [DataMember] 11 | public Node Next { get; set; } 12 | [DataMember] 13 | public Node Previous { get; set; } 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Q73/Serialization/Person.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.Serialization; 4 | using System.Text; 5 | 6 | namespace Serialization 7 | { 8 | [DataContract] 9 | public class Person 10 | { 11 | [DataMember] 12 | public string FirstName { get; set; } 13 | [DataMember] 14 | public string LastName { get; set; } 15 | public int Age 16 | { 17 | get 18 | { 19 | var today = DateTime.Today; 20 | var age = today.Year - dateOfBirth.Year; 21 | if (dateOfBirth.AddYears(age) > today) 22 | { 23 | age--; 24 | } 25 | return age; 26 | } 27 | } 28 | [DataMember] 29 | protected DateTime dateOfBirth; 30 | 31 | public Person(string firstName, string lastName, DateTime dateOfBirth) 32 | { 33 | FirstName = firstName; 34 | LastName = lastName; 35 | this.dateOfBirth = dateOfBirth; 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Q73/Serialization/PersonNoAttributes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Serialization 4 | { 5 | public class PersonNoAttributes 6 | { 7 | public string FirstName { get; set; } 8 | public string LastName { get; set; } 9 | public DateTime DateOfBirth { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Q73/Serialization/PersonWithAttributes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Xml.Serialization; 5 | 6 | namespace Serialization 7 | { 8 | [XmlRoot("person")] 9 | public class PersonWithAttributes 10 | { 11 | [XmlElement("name")] 12 | public string FirstName { get; set; } 13 | [XmlIgnore] 14 | public string LastName { get; set; } 15 | [XmlAttribute("dateOfBirth")] 16 | public DateTime DateOfBirth { get; set; } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Q73/Serialization/SerializablePerson.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Serialization 6 | { 7 | [Serializable] 8 | public class SerializablePerson 9 | { 10 | public string FirstName { get; set; } 11 | public string LastName { get; set; } 12 | public int Age 13 | { 14 | get 15 | { 16 | var today = DateTime.Today; 17 | var age = today.Year - dateOfBirth.Year; 18 | if (dateOfBirth.AddYears(age) > today) 19 | { 20 | age--; 21 | } 22 | return age; 23 | } 24 | } 25 | protected DateTime dateOfBirth; 26 | 27 | public SerializablePerson(string firstName, string lastName, DateTime dateOfBirth) 28 | { 29 | FirstName = firstName; 30 | LastName = lastName; 31 | this.dateOfBirth = dateOfBirth; 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Q73/Serialization/Serialization.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q74/Plugins/CustomPlugin.cs: -------------------------------------------------------------------------------- 1 | namespace Plugins 2 | { 3 | public class CustomPlugin : IPlugin 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Q74/Plugins/IPlugin.cs: -------------------------------------------------------------------------------- 1 | namespace Plugins 2 | { 3 | public interface IPlugin 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Q74/Plugins/Plugins.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Q74/Reflection/Reflection.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Q75/AddOns/AddOns.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Q75/AddOns/Pluggable.cs: -------------------------------------------------------------------------------- 1 | using Contracts; 2 | using System; 3 | 4 | namespace AddOns 5 | { 6 | public class Pluggable : IPluggable 7 | { 8 | public string GetString() 9 | { 10 | return "Dynamically loaded"; 11 | } 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Q75/Contracts/Contracts.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Q75/Contracts/IPluggable.cs: -------------------------------------------------------------------------------- 1 | namespace Contracts 2 | { 3 | public interface IPluggable 4 | { 5 | string GetString(); 6 | } 7 | 8 | } 9 | -------------------------------------------------------------------------------- /Q75/ReflectionDangers/ReflectionDangers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Q76/CustomAttributes/CustomAttributes.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q76/CustomAttributes/IValidatable.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CustomAttributes 4 | { 5 | public interface IValidatable 6 | { 7 | Dictionary GetValidationErrors(); 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Q76/CustomAttributes/NotNullableAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CustomAttributes 4 | { 5 | [AttributeUsage(AttributeTargets.Property)] 6 | public class NotNullableAttribute : Attribute 7 | { 8 | public string ErrorMessage { get; set; } = "Null value is not allowed."; 9 | 10 | public NotNullableAttribute() 11 | { } 12 | 13 | public NotNullableAttribute(string errorMessage) 14 | { 15 | ErrorMessage = errorMessage; 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Q76/CustomAttributes/Person.cs: -------------------------------------------------------------------------------- 1 | namespace CustomAttributes 2 | { 3 | public class Person 4 | { 5 | [NotNullable] 6 | public string FirstName { get; set; } 7 | [NotNullable("LastName is required.")] 8 | public string LastName { get; set; } 9 | public string MiddleName { get; set; } 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Q76/CustomAttributes/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CustomAttributes 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | AttributeBasedValidation(); 10 | MethodBasedValidation(); 11 | } 12 | 13 | private static void AttributeBasedValidation() 14 | { 15 | var person = new Person(); 16 | var errors = person.GetValidationErrors(); 17 | } 18 | 19 | private static void MethodBasedValidation() 20 | { 21 | var person = new ValidatablePerson(); 22 | var errors = person.GetValidationErrors(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Q76/CustomAttributes/ValidatablePerson.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace CustomAttributes 6 | { 7 | public class ValidatablePerson : IValidatable 8 | { 9 | public string FirstName { get; set; } 10 | public string LastName { get; set; } 11 | public string MiddleName { get; set; } 12 | 13 | public Dictionary GetValidationErrors() 14 | { 15 | var errors = new Dictionary(); 16 | 17 | if (FirstName == null) 18 | { 19 | errors.Add(nameof(FirstName), "Null value is not allowed."); 20 | } 21 | if (LastName == null) 22 | { 23 | errors.Add(nameof(LastName), "LastName is required."); 24 | } 25 | 26 | return errors; 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Q76/CustomAttributes/ValidationExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace CustomAttributes 5 | { 6 | public static class ValidationExtensions 7 | { 8 | public static Dictionary GetValidationErrors(this object instance) 9 | { 10 | var errors = new Dictionary(); 11 | 12 | var attributeType = typeof(NotNullableAttribute); 13 | var instanceType = instance.GetType(); 14 | var properties = instanceType.GetProperties(); 15 | foreach (var property in properties) 16 | { 17 | var attribute = (NotNullableAttribute)Attribute.GetCustomAttribute(property, attributeType); 18 | if (attribute != null) 19 | { 20 | var propertyValue = property.GetValue(instance); 21 | if (propertyValue == null) 22 | { 23 | errors.Add(property.Name, attribute.ErrorMessage); 24 | } 25 | } 26 | } 27 | 28 | return errors; 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Q77/CSharp2/CSharp2.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q77/CSharp3/CSharp3.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q77/CSharp3/NameAndAge.cs: -------------------------------------------------------------------------------- 1 | namespace CSharp3 2 | { 3 | public class NameAndAge 4 | { 5 | private string name; 6 | public string Name 7 | { 8 | get 9 | { 10 | return name; 11 | } 12 | set 13 | { 14 | name = value; 15 | } 16 | } 17 | 18 | private int age; 19 | public int Age 20 | { 21 | get 22 | { 23 | return age; 24 | } 25 | set 26 | { 27 | age = value; 28 | } 29 | } 30 | 31 | public NameAndAge(string name, int age) 32 | { 33 | Name = name; 34 | Age = age; 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Q77/CSharp3/Person.cs: -------------------------------------------------------------------------------- 1 | namespace CSharp3 2 | { 3 | public class Person 4 | { 5 | public string Name { get; set; } 6 | public string Surname { get; set; } 7 | public int Age { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Q77/CSharp3/Program.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace CSharp3 5 | { 6 | class Program 7 | { 8 | private static readonly List persons = new List(); 9 | 10 | static void Main(string[] args) 11 | { 12 | After(); 13 | Before(); 14 | } 15 | 16 | private static void After() 17 | { 18 | var minors = persons.Where(person => person.Age < 18) 19 | .Select(person => new { person.Name, person.Age }) 20 | .ToList(); 21 | 22 | } 23 | 24 | private static void Before() 25 | { 26 | List minors = new List(); 27 | foreach (Person person in persons) 28 | { 29 | if (person.Age > 18) 30 | { 31 | minors.Add(new NameAndAge(person.Name, person.Age)); 32 | } 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Q77/CSharp4/CSharp4.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q77/CSharp5/CSharp5.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7.1 7 | 8 | 9 | 10 | 11 | Always 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Q77/CSharp5/TextFile1.txt: -------------------------------------------------------------------------------- 1 | A sentence with a couple of words. -------------------------------------------------------------------------------- /Q77/CSharp6/CSharp6.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q77/CSharp7/Bow.cs: -------------------------------------------------------------------------------- 1 | namespace CSharp7 2 | { 3 | public class Bow : IWeapon 4 | { 5 | public int Damage { get; set; } 6 | public int Weight { get; set; } 7 | public int Arrows { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Q77/CSharp7/CSharp7.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q77/CSharp7/Enemy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace CSharp7 6 | { 7 | public class Enemy : IEnemy 8 | { 9 | public int Health { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Q77/CSharp7/IEnemy.cs: -------------------------------------------------------------------------------- 1 | namespace CSharp7 2 | { 3 | public interface IEnemy 4 | { 5 | int Health { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Q77/CSharp7/IWeapon.cs: -------------------------------------------------------------------------------- 1 | namespace CSharp7 2 | { 3 | public interface IWeapon 4 | { 5 | int Damage { get; set; } 6 | int Weight { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Q77/CSharp7/Inventory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace CSharp7 6 | { 7 | public class Inventory 8 | { 9 | public int Weight { get; set; } 10 | public int Count { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Q77/CSharp7/Sword.cs: -------------------------------------------------------------------------------- 1 | namespace CSharp7 2 | { 3 | public class Sword : IWeapon 4 | { 5 | public int Damage { get; set; } 6 | public int Weight { get; set; } 7 | public int Durability { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /Q78/BestCs6Features/AsyncResource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace BestCs6Features 5 | { 6 | public class AsyncResource 7 | { 8 | internal Task OpenAsync(bool throwException) 9 | { 10 | throw new NotImplementedException(); 11 | } 12 | 13 | internal Task LogAsync(Exception exceptionToLog) 14 | { 15 | //throw new NotImplementedException(); 16 | return Task.FromResult(0); 17 | } 18 | 19 | internal Task CloseAsync() 20 | { 21 | //throw new NotImplementedException(); 22 | return Task.FromResult(0); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Q78/BestCs6Features/BestCs6Features.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q78/BestCs6Features/PropertyChangeNotifier.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace BestCs6Features 4 | { 5 | class PropertyChangeNotifier : INotifyPropertyChanged 6 | { 7 | public event PropertyChangedEventHandler PropertyChanged; 8 | 9 | private void NotifyPropertyChangedAfter(string propertyName) 10 | { 11 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 12 | } 13 | 14 | private void NotifyPropertyChangedBefore(string propertyName) 15 | { 16 | if (PropertyChanged != null) 17 | { 18 | PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 19 | } 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Q78/Q78.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BestCs6Features", "BestCs6Features\BestCs6Features.csproj", "{BE7FC19B-B54F-442B-B001-819188FEB852}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {BE7FC19B-B54F-442B-B001-819188FEB852}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {BE7FC19B-B54F-442B-B001-819188FEB852}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {BE7FC19B-B54F-442B-B001-819188FEB852}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {BE7FC19B-B54F-442B-B001-819188FEB852}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {A1193749-0136-4948-BD9E-8875E90A9E32} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q79/Q79.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tuples", "Tuples\Tuples.csproj", "{F7BB4287-F666-4D0F-9B6C-6E39D1F65187}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {F7BB4287-F666-4D0F-9B6C-6E39D1F65187}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {F7BB4287-F666-4D0F-9B6C-6E39D1F65187}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {F7BB4287-F666-4D0F-9B6C-6E39D1F65187}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {F7BB4287-F666-4D0F-9B6C-6E39D1F65187}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {4D8A3DD9-BEAB-4EBE-B270-373321314397} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q79/Tuples/IWeapon.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Tuples 6 | { 7 | public interface IWeapon 8 | { 9 | int Weight { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Q79/Tuples/Person.cs: -------------------------------------------------------------------------------- 1 | namespace Tuples 2 | { 3 | public class Person 4 | { 5 | public string FirstName { get; set; } 6 | public string LastName { get; set; } 7 | 8 | public void Deconstruct(out string name, out string surname) 9 | { 10 | name = FirstName; 11 | surname = LastName; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Q79/Tuples/PersonExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Tuples 2 | { 3 | public static class PersonExtensions 4 | { 5 | public static void Deconstruct(this Person person, out string name, out string surname) 6 | { 7 | name = person.FirstName; 8 | surname = person.LastName; 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Q79/Tuples/Tuples.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7.1 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Q80/LocalFunctions/LocalFunctions.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q81/PatternMatching/Bow.cs: -------------------------------------------------------------------------------- 1 | namespace PatternMatching 2 | { 3 | internal class Bow : IWeapon 4 | { 5 | public int Arrows { get; set; } 6 | public int Damage { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Q81/PatternMatching/Enemy.cs: -------------------------------------------------------------------------------- 1 | namespace PatternMatching 2 | { 3 | class Enemy : IEnemy 4 | { 5 | public int Health { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Q81/PatternMatching/IEnemy.cs: -------------------------------------------------------------------------------- 1 | namespace PatternMatching 2 | { 3 | public interface IEnemy 4 | { 5 | int Health { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Q81/PatternMatching/IWeapon.cs: -------------------------------------------------------------------------------- 1 | namespace PatternMatching 2 | { 3 | public interface IWeapon 4 | { 5 | int Damage { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Q81/PatternMatching/PatternMatching.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q81/PatternMatching/Sword.cs: -------------------------------------------------------------------------------- 1 | namespace PatternMatching 2 | { 3 | internal class Sword : IWeapon 4 | { 5 | public int Durability { get; set; } 6 | public int Damage { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Q82/Discards/Bow.cs: -------------------------------------------------------------------------------- 1 | namespace Discards 2 | { 3 | public class Bow : IWeapon 4 | { 5 | public int Weight { get; set; } 6 | public int Arrows { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Q82/Discards/Discards.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q82/Discards/IWeapon.cs: -------------------------------------------------------------------------------- 1 | namespace Discards 2 | { 3 | public interface IWeapon 4 | { 5 | int Weight { get; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Q82/Discards/Person.cs: -------------------------------------------------------------------------------- 1 | namespace Discards 2 | { 3 | public class Person 4 | { 5 | public string FirstName { get; set; } 6 | public string LastName { get; set; } 7 | public int Age { get; set; } 8 | 9 | public void Deconstruct(out string name, out string surname, out int age) 10 | { 11 | name = FirstName; 12 | surname = LastName; 13 | age = Age; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Q82/Discards/Sword.cs: -------------------------------------------------------------------------------- 1 | namespace Discards 2 | { 3 | public class Sword : IWeapon 4 | { 5 | public int Weight { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Q82/Q82.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.168 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discards", "Discards\Discards.csproj", "{0630FB5C-317D-4FC5-84BF-C968F4BB52A3}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {0630FB5C-317D-4FC5-84BF-C968F4BB52A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {0630FB5C-317D-4FC5-84BF-C968F4BB52A3}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {0630FB5C-317D-4FC5-84BF-C968F4BB52A3}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {0630FB5C-317D-4FC5-84BF-C968F4BB52A3}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {40F2C86D-DB0B-4BF1-AEAB-4B1B2197471A} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q83/AsyncMain/AsyncMain.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7.1 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Q83/AsyncMain/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace AsyncMain 5 | { 6 | class Program 7 | { 8 | static async Task Main(string[] args) 9 | { 10 | Console.WriteLine("Program start"); 11 | for (int i = 0; i < 10; i++) 12 | { 13 | await Task.Delay(1000); 14 | Console.WriteLine($"{i + 1} seconds passed."); 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Q83/AsyncValueTask/AsyncValueTask.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7.1 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Q83/AsyncValueTask/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace AsyncValueTask 5 | { 6 | class Program 7 | { 8 | static async Task Main(string[] args) 9 | { 10 | var formTask = await ReturnsTask(); 11 | var formValueTask = await ReturnsValueTask(); 12 | } 13 | 14 | public static async Task ReturnsTask() 15 | { 16 | await Task.Delay(10); 17 | return 42; 18 | } 19 | 20 | public static async ValueTask ReturnsValueTask() 21 | { 22 | await Task.Delay(10); 23 | return 42; 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Q83/SyncMain/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | namespace SyncMain 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | MainAsync(args).GetAwaiter().GetResult(); 11 | } 12 | 13 | static async Task MainAsync(string[] args) 14 | { 15 | // asynchronous code 16 | } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Q83/SyncMain/SyncMain.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q84/ValuesByReference/ReadOnlyStruct.cs: -------------------------------------------------------------------------------- 1 | namespace ValuesByReference 2 | { 3 | readonly struct ReadonlyStruct 4 | { 5 | public int ImmutableProperty { get; } 6 | //public int MutableProperty { get; set; } // will not compile 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Q84/ValuesByReference/Terrain.cs: -------------------------------------------------------------------------------- 1 | namespace ValuesByReference 2 | { 3 | public class Terrain 4 | { 5 | public static Terrain Get() 6 | { 7 | return new Terrain(); 8 | } 9 | 10 | private TerrainType[,] terrain = new TerrainType[8, 8]; 11 | 12 | public ref TerrainType GetAt(int x, int y) => ref terrain[x, y]; 13 | 14 | public void BurnAt(int x, int y) 15 | { 16 | terrain[x, y] = TerrainType.Dirt; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Q84/ValuesByReference/TerrainType.cs: -------------------------------------------------------------------------------- 1 | namespace ValuesByReference 2 | { 3 | public enum TerrainType 4 | { 5 | Grass, 6 | Dirt 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Q84/ValuesByReference/ValuesByReference.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.2 5 | 6 | false 7 | 8 | 7.3 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Q84/ValuesByReference/Vector3.cs: -------------------------------------------------------------------------------- 1 | namespace ValuesByReference 2 | { 3 | public struct Vector3 4 | { 5 | public int X { get; set; } 6 | public int Y { get; set; } 7 | public int Z { get; set; } 8 | 9 | public Vector3(int x, int y, int z) 10 | { 11 | X = x; 12 | Y = y; 13 | Z = z; 14 | } 15 | 16 | public void Scale(int factor) 17 | { 18 | X *= factor; 19 | Y *= factor; 20 | Z *= factor; 21 | } 22 | 23 | // other struct members omitted for brevity 24 | 25 | private static readonly Vector3 zero = new Vector3(0, 0, 0); 26 | public static ref readonly Vector3 Zero => ref zero; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Q85/ErrorHandling/ErrorHandling.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.2 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Q85/README.md: -------------------------------------------------------------------------------- 1 | `WebApp`, `WindowsFormsApp` and `WpfApp` are Windows specific .NET framework projects and require Visual Studio 2017 to run. 2 | 3 | If `WebApp` starts with a generic ASP.NET error page instead of the custom error page, _Clean_ and _Rebuild_ the project. -------------------------------------------------------------------------------- /Q85/WebApp/App_Start/FilterConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Mvc; 3 | 4 | namespace WebApp 5 | { 6 | public class FilterConfig 7 | { 8 | public static void RegisterGlobalFilters(GlobalFilterCollection filters) 9 | { 10 | filters.Add(new HandleErrorAttribute()); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Q85/WebApp/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace WebApp 9 | { 10 | public class RouteConfig 11 | { 12 | public static void RegisterRoutes(RouteCollection routes) 13 | { 14 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 15 | 16 | routes.MapRoute( 17 | name: "Default", 18 | url: "{controller}/{action}/{id}", 19 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 20 | ); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Q85/WebApp/Content/Site.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 50px; 3 | padding-bottom: 20px; 4 | } 5 | 6 | /* Set padding to keep content from hitting the edges */ 7 | .body-content { 8 | padding-left: 15px; 9 | padding-right: 15px; 10 | } 11 | 12 | /* Override the default bootstrap behavior where horizontal description lists 13 | will truncate terms that are too long to fit in the left column 14 | */ 15 | .dl-horizontal dt { 16 | white-space: normal; 17 | } 18 | 19 | /* Set width on the form input elements since they're 100% wide by default */ 20 | input, 21 | select, 22 | textarea { 23 | max-width: 280px; 24 | } 25 | -------------------------------------------------------------------------------- /Q85/WebApp/Controllers/ErrorController.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Mvc; 2 | 3 | namespace WebApp.Controllers 4 | { 5 | public class ErrorController : Controller 6 | { 7 | // GET: Error 8 | public ActionResult Index() 9 | { 10 | return View(); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Q85/WebApp/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | 7 | namespace WebApp.Controllers 8 | { 9 | public class HomeController : Controller 10 | { 11 | public ActionResult Index() 12 | { 13 | throw new Exception(); 14 | return View(); 15 | } 16 | 17 | public ActionResult About() 18 | { 19 | ViewBag.Message = "Your application description page."; 20 | 21 | return View(); 22 | } 23 | 24 | public ActionResult Contact() 25 | { 26 | ViewBag.Message = "Your contact page."; 27 | 28 | return View(); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Q85/WebApp/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="WebApp.MvcApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /Q85/WebApp/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Optimization; 7 | using System.Web.Routing; 8 | 9 | namespace WebApp 10 | { 11 | public class MvcApplication : System.Web.HttpApplication 12 | { 13 | protected void Application_Start() 14 | { 15 | AreaRegistration.RegisterAllAreas(); 16 | FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 17 | RouteConfig.RegisterRoutes(RouteTable.Routes); 18 | BundleConfig.RegisterBundles(BundleTable.Bundles); 19 | } 20 | protected void Application_Error(object sender, EventArgs e) 21 | { 22 | var exception = Server.GetLastError(); // get exception 23 | Response.Redirect("error"); // show error page to user 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Q85/WebApp/Views/Error/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewBag.Title = "Error"; 3 | } 4 | 5 |
6 | Error 7 |
8 |
9 |
10 | An unexpected error has occurred. Please contact the system administrator. 11 |
12 | @if (Model != null && HttpContext.Current.IsDebuggingEnabled) 13 | { 14 |
15 |

16 | Exception: @Model.Exception.Message
17 | Controller: @Model.ControllerName
18 | Action: @Model.ActionName 19 |

20 |
21 |
22 |                     @Model.Exception.StackTrace
23 |                 
24 |
25 |
26 | } 27 |
-------------------------------------------------------------------------------- /Q85/WebApp/Views/Home/About.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewBag.Title = "About"; 3 | } 4 |

@ViewBag.Title.

5 |

@ViewBag.Message

6 | 7 |

Use this area to provide additional information.

8 | -------------------------------------------------------------------------------- /Q85/WebApp/Views/Home/Contact.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewBag.Title = "Contact"; 3 | } 4 |

@ViewBag.Title.

5 |

@ViewBag.Message

6 | 7 |
8 | One Microsoft Way
9 | Redmond, WA 98052-6399
10 | P: 11 | 425.555.0100 12 |
13 | 14 |
15 | Support: Support@example.com
16 | Marketing: Marketing@example.com 17 |
-------------------------------------------------------------------------------- /Q85/WebApp/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Error 6 | 7 | 8 |
9 |

Error.

10 |

An error occurred while processing your request.

11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /Q85/WebApp/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/Views/Shared/_Layout.cshtml"; 3 | } 4 | -------------------------------------------------------------------------------- /Q85/WebApp/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnetcurry/csharpbook/7eb18e67855e9e74db865027328438365ffe5eae/Q85/WebApp/favicon.ico -------------------------------------------------------------------------------- /Q85/WebApp/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnetcurry/csharpbook/7eb18e67855e9e74db865027328438365ffe5eae/Q85/WebApp/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /Q85/WebApp/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnetcurry/csharpbook/7eb18e67855e9e74db865027328438365ffe5eae/Q85/WebApp/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /Q85/WebApp/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnetcurry/csharpbook/7eb18e67855e9e74db865027328438365ffe5eae/Q85/WebApp/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /Q85/WebApp/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnetcurry/csharpbook/7eb18e67855e9e74db865027328438365ffe5eae/Q85/WebApp/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /Q85/WindowsFormsApp/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Q85/WindowsFormsApp/PersonEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace WindowsFormsApp 8 | { 9 | class PersonEntity 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Q85/WindowsFormsApp/PersonModel.cs: -------------------------------------------------------------------------------- 1 | namespace WindowsFormsApp 2 | { 3 | public class PersonModel 4 | { 5 | public object Id { get; internal set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Q85/WindowsFormsApp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace WindowsFormsApp 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new Form1()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Q85/WindowsFormsApp/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Q85/WpfApp/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Q85/WpfApp/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Q85/WpfApp/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | using System.Windows; 9 | using System.Windows.Threading; 10 | 11 | namespace WpfApp 12 | { 13 | /// 14 | /// Interaction logic for App.xaml 15 | /// 16 | public partial class App : Application 17 | { 18 | private string logPath = "errors.txt"; 19 | 20 | public App() 21 | { 22 | DispatcherUnhandledException += App_DispatcherUnhandledException; 23 | } 24 | 25 | private void App_DispatcherUnhandledException(object sender, 26 | DispatcherUnhandledExceptionEventArgs e) 27 | { 28 | var exception = e.Exception; // get exception 29 | // ... show the error to the user 30 | 31 | File.AppendAllText(logPath, exception.ToString()); 32 | 33 | e.Handled = true; // prevent the application from crashing 34 | Shutdown(); // quit the application in a controlled way 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Q85/WpfApp/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Q85/WpfApp/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Navigation; 14 | using System.Windows.Shapes; 15 | 16 | namespace WpfApp 17 | { 18 | /// 19 | /// Interaction logic for MainWindow.xaml 20 | /// 21 | public partial class MainWindow : Window 22 | { 23 | public MainWindow() 24 | { 25 | InitializeComponent(); 26 | } 27 | 28 | private void OnClickException(object sender, RoutedEventArgs e) 29 | { 30 | throw new Exception(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Q85/WpfApp/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Q86/FunctionalProgramming/FunctionalProgramming.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.2 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Q86/FunctionalProgramming/PersonExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace FunctionalProgramming 2 | { 3 | public static class PersonExtensions 4 | { 5 | public static Person Rename(this Person person, string firstName) 6 | { 7 | return person.With(firstName: firstName); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Q87/Cs8Features/AsyncEnumerableBoilerPlate.cs: -------------------------------------------------------------------------------- 1 | namespace System.Threading.Tasks 2 | { 3 | using System.Runtime.CompilerServices; 4 | using System.Threading.Tasks.Sources; 5 | 6 | internal struct ManualResetValueTaskSourceLogic 7 | { 8 | private ManualResetValueTaskSourceCore _core; 9 | public ManualResetValueTaskSourceLogic(IStrongBox> parent) : this() { } 10 | public short Version => _core.Version; 11 | public TResult GetResult(short token) => _core.GetResult(token); 12 | public ValueTaskSourceStatus GetStatus(short token) => _core.GetStatus(token); 13 | public void OnCompleted(Action continuation, object state, short token, ValueTaskSourceOnCompletedFlags flags) => _core.OnCompleted(continuation, state, token, flags); 14 | public void Reset() => _core.Reset(); 15 | public void SetResult(TResult result) => _core.SetResult(result); 16 | public void SetException(Exception error) => _core.SetException(error); 17 | } 18 | } 19 | 20 | namespace System.Runtime.CompilerServices 21 | { 22 | internal interface IStrongBox { ref T Value { get; } } 23 | } 24 | -------------------------------------------------------------------------------- /Q87/Cs8Features/Cs8Features.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | false 7 | 8 | 8.0 9 | true 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Q87/Cs8Features/IWeapon.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Cs8Features 6 | { 7 | public interface IWeapon 8 | { 9 | void Repair(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Q87/Q87.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28407.52 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cs8Features", "Cs8Features\Cs8Features.csproj", "{3739DB4C-9E59-4B11-AFC6-E0A268D232AD}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {3739DB4C-9E59-4B11-AFC6-E0A268D232AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {3739DB4C-9E59-4B11-AFC6-E0A268D232AD}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {3739DB4C-9E59-4B11-AFC6-E0A268D232AD}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {3739DB4C-9E59-4B11-AFC6-E0A268D232AD}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {F939D033-D5C2-4B15-8F4B-EC5439B0971E} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Q87/README.md: -------------------------------------------------------------------------------- 1 | This example requires .NET Core 3.0 Preview 1 and Visual Studio 2019 Preview 1 to run because `Cs8Features` is a .NET Core 3.0 project and uses of C# 8.0 features. --------------------------------------------------------------------------------