├── .editorconfig ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ └── config.yml ├── PULL_REQUEST_TEMPLATE.md ├── dependabot.yml └── workflows │ ├── CleanupCache.yml │ ├── Code-Analysis.yml │ ├── LocalesTest.yml │ ├── build-and-test.yml │ └── sync-version-branches.yml ├── .gitignore ├── .runsettings ├── .vscode ├── cSpell.json └── extensions.json ├── Common.props ├── Directory.Build.props ├── Directory.Build.targets ├── Directory.Packages.props ├── Errata.md ├── EssentialCSharp.sln ├── LICENSE ├── Project.code-workspace ├── README.md ├── RenumberListingsInformation.txt ├── TODO.md ├── Update-CSProj.ps1 ├── Utilities ├── SetProjectRenameAlias.ps1 ├── UpdateCsProj.ps1 └── Write-PSObject.ps1 ├── after.EssentialCSharp.sln.targets ├── build.cmd ├── build.ps1 ├── dotnet-tests.sh ├── exclusion.dic ├── global.json ├── src ├── Chapter.props ├── Chapter01.Tests │ ├── Chapter01.Tests.csproj │ ├── Listing01.01.Tests.cs │ ├── Listing01.03.Tests.cs │ ├── Listing01.04.Tests.cs │ ├── Listing01.05.Tests.cs │ ├── Listing01.06.Tests.cs │ ├── Listing01.08.Tests.cs │ ├── Listing01.09.Tests.cs │ ├── Listing01.10.Tests.cs │ ├── Listing01.11.Tests.cs │ ├── Listing01.12.Tests.cs │ ├── Listing01.13.Tests.cs │ ├── Listing01.14.Tests.cs │ ├── Listing01.15.Tests.cs │ ├── Listing01.16.Tests.cs │ ├── Listing01.17.Tests.cs │ ├── Listing01.18.Tests.cs │ ├── Listing01.19.Tests.cs │ ├── Listing01.20.Tests.cs │ ├── Listing01.21.Tests.cs │ └── Tests.cs.backup ├── Chapter01 │ ├── Chapter01.csproj │ ├── Listing01.01.HelloWorldInC#.cs │ ├── Listing01.01.HelloWorldInC#.ps1 │ ├── Listing01.02.SampleNETCoreConsoleProjectFile.xml │ ├── Listing01.03.MultipleStatementsOneOneLine.cs │ ├── Listing01.04.MultipleStatementsOnSeparateLines.cs │ ├── Listing01.05.SplittingAStatementAcrossMultipleLines.cs │ ├── Listing01.06.HelloWorldInC#.cs │ ├── Listing01.07.BasicClassDeclaration.cs │ ├── Listing01.08.BreakingApartHelloWorld.cs │ ├── Listing01.09.TheMainMethodWithParametersAndAReturn.cs │ ├── Listing01.10.NoIndentationFormatting.cs │ ├── Listing01.11.RemovingWhitespace.cs │ ├── Listing01.12.DeclaringAndAssigningAVariable.cs │ ├── Listing01.13.DeclaringTwoVariablesWithinOneStatement.cs │ ├── Listing01.14.ChangingTheValueOfAVariable.cs │ ├── Listing01.15.AssignmentReturningAValueThatCanBeassignedAgain.cs │ ├── Listing01.16.UsingSystemConsoleReadLine.cs │ ├── Listing01.17.UsingSystemConsoleRead.cs │ ├── Listing01.18.FormattingUsingStringInterpolation.cs │ ├── Listing01.19.FormattingUsingCompositeFormatting.cs │ ├── Listing01.20.SwappingTheIndexedPlaceholdersAndCorrespondingVariables.cs │ ├── Listing01.21.CommentingYourCode.cs │ ├── Listing01.22.SampleCILOutput.cs │ └── TopLevelStatementWrapperForListing01.01.cs ├── Chapter02.Tests │ ├── Chapter02.Tests.csproj │ ├── Listing02.01.Tests.cs │ ├── Listing02.02.Tests.cs │ ├── Listing02.03.Tests.cs │ ├── Listing02.04.Tests.cs │ ├── Listing02.05.Tests.cs │ ├── Listing02.06.Tests.cs │ ├── Listing02.07.Tests.cs │ ├── Listing02.08.Tests.cs │ ├── Listing02.09.Tests.cs │ ├── Listing02.10.Tests.cs │ ├── Listing02.11.Tests.cs │ ├── Listing02.12.Tests.cs │ ├── Listing02.13.Tests.cs │ ├── Listing02.14.Tests.cs │ ├── Listing02.15.Tests.cs │ ├── Listing02.16.Tests.cs │ ├── Listing02.17.Tests.cs │ ├── Listing02.18.Tests.cs │ ├── Listing02.19.Tests.cs │ ├── Listing02.20.Tests.cs │ ├── Listing02.21.Tests.cs │ ├── Listing02.22.Tests.cs │ ├── Listing02.23.Tests.cs │ ├── Listing02.24.Tests.cs │ ├── Listing02.25.Tests.cs │ ├── Listing02.26.Tests.cs │ ├── Listing02.27.Tests.cs │ ├── Listing02.28.Tests.cs │ ├── Listing02.29.Tests.cs │ ├── Listing02.30.Tests.cs │ ├── Listing02.31.Tests.cs │ ├── Listing02.32.Tests.cs │ ├── Listing02.33.Tests.cs │ ├── Listing02.34.Tests.cs │ ├── Listing02.35.Tests.cs │ ├── Listing02.36.Tests.cs │ ├── NetCoreTests.cs │ └── Tests.cs.backup ├── Chapter02 │ ├── Chapter02.csproj │ ├── Listing02.01.SpecifyingLiteralValues.cs │ ├── Listing02.02.SpecifyingALiteralDouble.cs │ ├── Listing02.03.SpecifyingALiteralDecimal.cs │ ├── Listing02.04.UsingTheDigitSeparator.cs │ ├── Listing02.05.ExponentialNotation.cs │ ├── Listing02.06.HexadecimalLiteralValue.cs │ ├── Listing02.07.BinaryLiteralValue.cs │ ├── Listing02.08.ExamplesOfAHexadecimalFormatSpecifier.cs │ ├── Listing02.09.UsingStringFormat.cs │ ├── Listing02.10.CaseInsensitiveComparisonOfTwoStrings.cs │ ├── Listing02.11.DisplayingASingleQuoteUsingAnEscapeSequence.cs │ ├── Listing02.12.UsingUnicodeEncodingToDisplayASmileyFace.cs │ ├── Listing02.13.UsingTheNewlineCharacterToInsertANewline.cs │ ├── Listing02.14.DisplayingATriangleUsingAVerbatimStringLiteral.cs │ ├── Listing02.15.StringInterpolation.cs │ ├── Listing02.16.NewLinesWithinStringInterpolation.cs │ ├── Listing02.17.CombiningStringLiteralsWithInterpolation.cs │ ├── Listing02.18.SingleLineRawStringLiteral.cs │ ├── Listing02.19.RawStringLiteralWithInterpolation.cs │ ├── Listing02.20.DisplayingMobiusStripUsingRawStringLiteral.cs │ ├── Listing02.21.WorkingWithJSONUsingRawStringLiterals.cs │ ├── Listing02.22.UsingStringsLengthMember.cs │ ├── Listing02.23.Error-StringIsImmutable.cs │ ├── Listing02.24.WorkingWithStrings.cs │ ├── Listing02.25.AssigningNullToAString.cs │ ├── Listing02.26.ExplicitCastExample.cs │ ├── Listing02.27.OverflowingAnIntegerValue.cs │ ├── Listing02.28.ACheckedBlockExample.cs │ ├── Listing02.29.AnUncheckedBlockExample.cs │ ├── Listing02.30.NotUsingTheCastOperatorForAnImplicitCast.cs │ ├── Listing02.31.UsingTheCastOperatorForAnImplicitCast.cs │ ├── Listing02.32.UsingIntParseToConvertAStringToANumericDataType.cs │ ├── Listing02.33.TypeConversionUsingSystemConvert.cs │ ├── Listing02.34.UsingToStringToConvertToAString.cs │ ├── Listing02.35.UsingTryParseInPlaceOfAnInvalidCastException.cs │ └── Listing02.36.UsingTryParseWithInlineOut.cs ├── Chapter03.Tests │ ├── Chapter03.Tests.csproj │ ├── Listing03.01.Tests.cs │ ├── Listing03.02.DereferencingAnUnassignedVariable.Tests.cs │ ├── Listing03.03.Tests.cs │ ├── Listing03.05.Tests.cs │ ├── Listing03.19.Tests.cs │ ├── Listing03.23.Tests.cs │ ├── Listing03.24.Tests.cs │ ├── Listing03.26.Tests.cs │ ├── Listing03.27.Tests.cs │ ├── Listing03.28.Tests.cs │ ├── Listing03.31.Tests.cs │ ├── Table03.01.Tests.cs │ ├── Table03.02.Tests.cs │ └── Table03.03.Tests.cs ├── Chapter03 │ ├── Chapter03.csproj │ ├── Listing03.01.CheckingForNull.cs │ ├── Listing03.02.DereferencingAnUnassignedVariable.cs │ ├── Listing03.03.WorkingWithStrings.cs │ ├── Listing03.04.TheCSharpEquivalentOfCompilerGeneratedCILCodeForAValueTupleReturn.cs │ ├── Listing03.05.ImplicitLocalVariablesWithAnonymousTypes.cs │ ├── Listing03.06.DeclaringAnArray.cs │ ├── Listing03.07.DeclaringATwoDimensionalArray.cs │ ├── Listing03.08.ArrayDeclarationWithAssignment.cs │ ├── Listing03.09.ArrayAssignmentFollowingDeclaration.cs │ ├── Listing03.10.ArrayAssignmentWithNewDuringDeclaration.cs │ ├── Listing03.11.DeclarationAndAssignmentWithTheNewKeyword.cs │ ├── Listing03.12.AssigningWithoutLiteralValues.cs │ ├── Listing03.13.DefiningTheArraySizeAtRuntime.cs │ ├── Listing03.14.DeclaringATwoDimensionalArray.cs │ ├── Listing03.15.InitializingATwoDimensionalArrayOfIntegers.cs │ ├── Listing03.16.AMultidimensionalArrayWithInconsistentSizeCausingAnError.cs │ ├── Listing03.17.InitializingAThreeDimensionalArray.cs │ ├── Listing03.18.InitializingAJaggedArray.cs │ ├── Listing03.19.DeclaringAndAccessingAnArray.cs │ ├── Listing03.20.SwappingDataBetweenPositionsInAnArray.cs │ ├── Listing03.21.InitializingATwoDimensionalArrayOfIntegers.cs │ ├── Listing03.22.DeclaringAJaggedArray.cs │ ├── Listing03.23.RetrievingTheLengthOfAnArray.cs │ ├── Listing03.24.AccessingOutsideTheBoundsOfAnArrayThrowingAnException.cs │ ├── Listing03.25.UsingLengthMinus1InTheArrayIndex.cs │ ├── Listing03.26.Slicing.cs │ ├── Listing03.27.AdditionalArrayMethods.cs │ ├── Listing03.28.RetrievingAParticularDimensionsSize.cs │ ├── Listing03.29.LookingForCommandlineOptions.cs │ ├── Listing03.30.LookingForCommandlineOptionsSimplified.cs │ ├── Listing03.31.ReversingAString.cs │ ├── Table03.01.TupleDeclarationAndAssignment.cs │ ├── Table03.02.ArrayHighlights.cs │ ├── Table03.03.a.CommonArrayCodingErrors.cs │ ├── Table03.03.b.CommonArrayCodingErrors.cs │ ├── Table03.03.c.CommonArrayCodingErrors.cs │ ├── Table03.03.d.CommonArrayCodingErrors.cs │ ├── Table03.03.e.CommonArrayCodingErrors.cs │ ├── Table03.03.f.CommonArrayCodingErrors.cs │ ├── Table03.03.g.CommonArrayCodingErrors.cs │ ├── Table03.03.h.CommonArrayCodingErrors.cs │ ├── Table03.03.i.CommonArrayCodingErrors.cs │ └── Table03.03.j.CommonArrayCodingErrors.cs ├── Chapter04.Tests │ ├── Chapter04.Tests.csproj │ ├── Listing04.01.SimpleOperator.Tests.cs │ ├── Listing04.02.Negative.Tests.cs │ ├── Listing04.03.BinaryOperators.Tests.cs │ ├── Listing04.04.Tests.cs │ ├── Listing04.05.Tests.cs │ ├── Listing04.06.Tests.cs │ ├── Listing04.07.UnexpectedInequality.Tests.cs │ ├── Listing04.08.Tests.cs │ ├── Listing04.09.Tests.cs │ ├── Listing04.15.Tests.cs │ ├── Listing04.16.Tests.cs │ ├── Listing04.17.Tests.cs │ ├── Listing04.18.ComparingPrePostIncrementOperators.Tests.cs │ ├── Listing04.20.Tests.cs │ ├── Listing04.21.Tests.cs │ ├── Listing04.22.Tests.cs │ ├── Listing04.23.Tests.cs │ ├── Listing04.24.Tests.cs │ ├── Listing04.25.Tests.cs │ ├── Listing04.26.Tests.cs │ ├── Listing04.27.Tests.cs │ ├── Listing04.28.Tests.cs │ ├── Listing04.29.Tests.cs │ ├── Listing04.32.Tests.cs │ ├── Listing04.33.Tests.cs │ ├── Listing04.34.Tests.cs │ ├── Listing04.35.Tests.cs │ ├── Listing04.38.Tests.cs │ ├── Listing04.39.Tests.cs │ ├── Listing04.40.Tests.cs │ ├── Listing04.41.Tests.cs │ ├── Listing04.42.Tests.cs │ ├── Listing04.43.Tests.cs │ ├── Listing04.44.Tests.cs │ ├── Listing04.46.Tests.cs │ ├── Listing04.47.Tests.cs │ ├── Listing04.48.Tests.cs │ ├── Listing04.49.Tests.cs │ ├── Listing04.50.Tests.cs │ ├── Listing04.51.Tests.cs │ ├── Listing04.53.Tests.cs │ ├── Listing04.54.Tests.cs │ ├── Listing04.55.Tests.cs │ ├── Listing04.63.Tests.cs │ ├── Table04.01.Tests.cs │ └── Table04.04.CheckForNull.Tests.cs ├── Chapter04 │ ├── Chapter04.csproj │ ├── Listing04.01.SimpleOperator.cs │ ├── Listing04.02.Negative.cs │ ├── Listing04.03.BinaryOperators.cs │ ├── Listing04.04.NonNumericTypes.cs │ ├── Listing04.05.CharConcatenation.cs │ ├── Listing04.06.CharDifferences.cs │ ├── Listing04.07.UnexpectedInequality.cs │ ├── Listing04.08.DivisionByZero.cs │ ├── Listing04.09.BoundOverflow.cs │ ├── Listing04.10.Increment.cs │ ├── Listing04.11.IncrementOperator.cs │ ├── Listing04.12.OtherOperators.cs │ ├── Listing04.13.UnaryIncrement.cs │ ├── Listing04.14.UnaryDecrement.cs │ ├── Listing04.15.DisplayUnicode.cs │ ├── Listing04.16.PostIncrement.cs │ ├── Listing04.17.PreIncrement.cs │ ├── Listing04.18.ComparingPrefixAndPostfix.cs │ ├── Listing04.19.DeclaringConstants.cs │ ├── Listing04.20.ConstantInterpolatedStrings.cs │ ├── Listing04.21.IfElseStatement.cs │ ├── Listing04.22.NestedIf.cs │ ├── Listing04.23.IfElseSequence.cs │ ├── Listing04.24.NoCodeBlock.cs │ ├── Listing04.25.WithCodeBlock.cs │ ├── Listing04.26.RelyingOnIndentation.cs │ ├── Listing04.27.IfStatementWithCurlyBraces.cs │ ├── Listing04.28.OutOfScope.cs │ ├── Listing04.29.BooleanExpression.cs │ ├── Listing04.30.AssignmentAsCondition.cs │ ├── Listing04.31.AssignAsBool.cs │ ├── Listing04.32.EqualityOperator.cs │ ├── Listing04.33.OrOperator.cs │ ├── Listing04.34.AndOperator.cs │ ├── Listing04.35.LogicalNegationOperator.cs │ ├── Listing04.36.ConditionalOperator.cs │ ├── Listing04.37.NullCoalescingOperator.cs │ ├── Listing04.38.NullConditionalOperator.cs │ ├── Listing04.39.NullConditionalOperatorWithIndexOperator.cs │ ├── Listing04.40.RightShiftOperator.cs │ ├── Listing04.41.BitwiseOperators.cs │ ├── Listing04.42.StringRepresentationOfBinary.cs │ ├── Listing04.43.LogicalAssignmentOperators.cs │ ├── Listing04.44.WhileLoop.cs │ ├── Listing04.45.DoWhileLoop.cs │ ├── Listing04.46.ForLoop.cs │ ├── Listing04.47.ForWithMultipleExpressions.cs │ ├── Listing04.48.DeterminingRemainingMoves.cs │ ├── Listing04.49.InputValidation.cs │ ├── Listing04.50.SwitchStatement.cs │ ├── Listing04.51.BreakStatement.cs │ ├── Listing04.52.SettingABit.cs │ ├── Listing04.53.DeterminingEmailDomain.cs │ ├── Listing04.54.ReplacingContinueWithIf.cs │ ├── Listing04.55.GotoStatements.cs │ ├── Listing04.56.ExcludingCode.cs │ ├── Listing04.57.Directives.cs │ ├── Listing04.58.DefineDirective.cs │ ├── Listing04.59.WarningDirective.cs │ ├── Listing04.60.PragmaDirective.cs │ ├── Listing04.61.PragmaRestore.cs │ ├── Listing04.62.LineWarning.cs │ ├── Listing04.63.Regions.cs │ ├── Table04.01.ControlFlowStatements.cs │ ├── Table04.04.CheckForNull.cs │ └── TicTacToe.cs ├── Chapter05.Tests │ ├── Chapter05.Tests.csproj │ ├── Constants.cs │ ├── GlobalUsings.cs │ ├── Listing05.02.SimpleMethodCall.Tests.cs │ ├── Listing05.03.PassingAMethodReturnAsAParameterToAnotherMethodCall.Tests.cs │ ├── Listing05.04.DeclaringAMethod.Tests.cs │ ├── Listing05.05.Tests.cs │ ├── Listing05.06.ReturningMultipleValuesViaTuple.Tests.cs │ ├── Listing05.07.DeclaringALocalFunction.Tests.cs │ ├── Listing05.08.Tests.cs │ ├── Listing05.10.StringBuilderImplicitUsingStatements.Tests.cs │ ├── Listing05.12.UsingStaticDirective.Tests.cs │ ├── Listing05.15.PassingCommandLineArgumentsToMain.Tests.cs │ ├── Listing05.16.PassingVariablesByValue.Tests.cs │ ├── Listing05.17.PassingVariablesByReference.Tests.cs │ ├── Listing05.18.PassingVariablesOutOnly.Tests.cs │ ├── Listing05.19.ReturningAReference.Tests.cs │ ├── Listing05.20.PassingAVariableParameterList.Tests.cs │ ├── Listing05.21.CountingLinesGivenADirectory.Tests.cs │ ├── Listing05.22.CountingLinesUsingOverloading.Tests.cs │ ├── Listing05.23.MethodsWithOptionalParameters.Tests.cs │ ├── Listing05.24.SpecifyingParametersByName.Tests.cs │ ├── Listing05.25.ConvertingAStringToAnInt.Tests.cs │ ├── Listing05.26.CatchingAnException.Tests.cs │ ├── Listing05.27.FinallyWithoutCatch.Tests.cs │ ├── Listing05.28.GeneralCatchBlocks.Tests.cs │ ├── Listing05.29.ThrowingAnException.Tests.cs │ ├── Listing05.30.RethrowingAnException.Tests.cs │ ├── Listing05.31.ParameterValidationThrowingArgumentNullException.Tests.cs │ ├── Listing05.32.ParameterValidationWithArgumentNullException.ThrowIfNull.Tests.cs │ ├── Listing05.33.CustomParameterValidation.Tests.cs │ └── Listing05.34.TryCatch.Tests.cs ├── Chapter05 │ ├── Chapter05.csproj │ ├── Listing05.01.GroupingStatementsIntoMethods.cs │ ├── Listing05.02.SimpleMethodCall.cs │ ├── Listing05.03.PassingAMethodReturnAsAParameterToAnotherMehtodCall.cs │ ├── Listing05.04.DeclaringAMethod.cs │ ├── Listing05.05.AReturnStatementBeforeTheEndOfAmethod.cs │ ├── Listing05.06.ReturningMultipleValuesViaTuples.cs │ ├── Listing05.07.DeclaringALocalFunction.cs │ ├── Listing05.08.UsingDirectiveExample.cs │ ├── Listing05.09.ImplicitUsingsGeneratedGlocalUsingDeclaratives.cs │ ├── Listing05.10.StringBuilderImplicitUsingStatements.cs │ ├── Listing05.11.SampleConsoleProjectFileWithUsingElement.xml │ ├── Listing05.12.UsingStaticDirective.cs │ ├── Listing05.13.DeclaringATypeAlias.cs │ ├── Listing05.14.DeclaringATypeAliasWithTheSameName.cs │ ├── Listing05.15.PassingCommandLineArgumentsToMain.cs │ ├── Listing05.16.PassingVariablesByValue.cs │ ├── Listing05.17.PassingVariablesByReference.cs │ ├── Listing05.18.PassingVariablesOutOnly.cs │ ├── Listing05.19.ReturningAReference.cs │ ├── Listing05.20.PassingAVariableParameterList.cs │ ├── Listing05.21.CountingLinesGivenADirectory.cs │ ├── Listing05.22.CountingLinesUsingOverloading.cs │ ├── Listing05.23.MethodsWithOptionalParameters.cs │ ├── Listing05.24.SpecifyingParametersByName.cs │ ├── Listing05.25.ConvertingAStringToAnInt.cs │ ├── Listing05.26.CatchingAnException.cs │ ├── Listing05.27.FinallyWithoutCatch.cs │ ├── Listing05.28.GeneralCatchBlocks.cs │ ├── Listing05.29.ThrowingAnException.cs │ ├── Listing05.30.RethrowingAnException.cs │ ├── Listing05.31.ParameterValidationThrowingArgumentNullException.cs │ ├── Listing05.32.ParameterValidationWithArgumentNullException.ThrowIfNull.cs │ ├── Listing05.33.CustomParameterValidation.cs │ └── Listing05.34.TryCatch.cs ├── Chapter06.Tests │ ├── Chapter06.Tests.csproj │ ├── Listing06.01.Tests.cs │ ├── Listing06.06.AccessingFields.Tests.cs │ ├── Listing06.07.Tests.cs │ ├── Listing06.08.AccessingFieldsFromOutsideTheContainingClass.Tests.cs │ ├── Listing06.09.Tests.cs │ ├── Listing06.10.Tests.cs │ ├── Listing06.11.UsingThisWithAMethod.Tests.cs │ ├── Listing06.12.Tests.cs │ ├── Listing06.13.DataPersistenceToAFile.Tests.cs │ ├── Listing06.14.DataRetrievalFromAFile.Tests.cs │ ├── Listing06.15.Tests.cs │ ├── Listing06.16.GettersAndSetters.Tests.cs │ ├── Listing06.17.DefiningProperties.Tests.cs │ ├── Listing06.18.DefiningPropertiesWithExpressionBodiedMembers.Tests.cs │ ├── Listing06.19.AutomaticallyImplementedProperties.Tests.cs │ ├── Listing06.20.ProvidingPropertyValidation.Tests.cs │ ├── Listing06.21.Tests.cs │ ├── Listing06.22.DefiningProperties.Tests.cs │ ├── Listing06.23.Tests.cs │ ├── Listing06.26.DefiningAConstructor.Tests.cs │ ├── Listing06.27.CallingAConstructor.Tests.cs │ ├── Listing06.28.Tests.cs │ ├── Listing06.29.DefaultConstructorNoLongerAvailable.Tests.cs │ ├── Listing06.30.CallingAnObjectInitializerWithExplicitMemberAssignment.Tests.cs │ ├── Listing06.32.Tests.cs │ ├── Listing06.33.OverloadingAConstructor.Tests.cs │ ├── Listing06.34.CallingOneConstructorFromAnother.Tests.cs │ ├── Listing06.35.ProvidingAnInitializationMethod.Tests.cs │ ├── Listing06.36.ProvidingValidationOnNon-NullableProperty.Tests.cs │ ├── Listing06.37.Tests.cs │ ├── Listing06.39.SpecifyingRequiredMembersWithinTheObjectInitializer.Tests.cs │ ├── Listing06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.Tests.cs │ ├── Listing06.42.PotentialNullReturnWithMaybeNullAttribute.Tests.cs │ ├── Listing06.43.DefiningAndUsingADeconstructors.Tests.cs │ ├── Listing06.44.ImplicitlyInvokingDeconstructors.Tests.cs │ ├── Listing06.45.Tests.cs │ ├── Listing06.46.Tests.cs │ ├── Listing06.47.AccessingAStaticField.Tests.cs │ ├── Listing06.48.DefiningAStaticMethodOnDirectoryInfo.Tests.cs │ ├── Listing06.49.Tests.cs │ ├── Listing06.51.DeclaringAStaticClass.Tests.cs │ ├── Listing06.54.Tests.cs │ ├── Listing06.55.DeclaringAReadOnlyAutomaticallyImplementedProperty.Tests.cs │ ├── Listing06.56.DefiningANestedClass.Tests.cs │ └── Listing06.59.Tests.cs ├── Chapter06 │ ├── Chapter06.csproj │ ├── Listing06.01.DefiningAClass.cs │ ├── Listing06.02.DeclaringVariablesOfTheClassType.cs │ ├── Listing06.03.InstantiatingAClass.cs │ ├── Listing06.04.DeclaringFields.cs │ ├── Listing06.05.SettingInitialValuesOfFieldsAtDeclarationTime.cs │ ├── Listing06.06.AccessingFields.cs │ ├── Listing06.07.AccessingFieldsFromWithinTheContainingClass.cs │ ├── Listing06.08.AccessingFieldsFromOutsideTheContainingClass.cs │ ├── Listing06.09.UsingThisToIdentifyTheFieldsOwnerExplicitly.cs │ ├── Listing06.10.UsingThisToAvoidAmbiguity.cs │ ├── Listing06.11.UsingThisWithAMethod.cs │ ├── Listing06.12.PassingThisInAMethodCall.cs │ ├── Listing06.13.DataPersistenceToAFile.cs │ ├── Listing06.14.DataRetrievalFromAFile.cs │ ├── Listing06.15.UsingThePrivateAccessModifier.cs │ ├── Listing06.16.GettersAndSetters.cs │ ├── Listing06.17.DefiningProperties.cs │ ├── Listing06.18.DefiningPropertiesWithExpressionBodiedMembers.cs │ ├── Listing06.19.AutomaticallyImplementedProperties.cs │ ├── Listing06.20.ProvidingPropertyValidation.cs │ ├── Listing06.21.DefiningReadOnlyProperties.cs │ ├── Listing06.22.DefiningCalculatedProperties.cs │ ├── Listing06.23.PlacingAccessModifiersOnSetters.cs │ ├── Listing06.24.CILCodeResultingFromProperties.cs │ ├── Listing06.25.PropertiesAreAnExplicitConstructInCIL.cs │ ├── Listing06.26.DefiningAPrimaryConstructor.cs │ ├── Listing06.27.CallingAConstructor.cs │ ├── Listing06.28.DefiningAConstructor.cs │ ├── Listing06.29.DefaultConstructorNoLongerAvailable.cs │ ├── Listing06.30.CallingAnObjectInitializerWithExplicitMemberAssignment.cs │ ├── Listing06.31.CallingAnObjectInitializer.cs │ ├── Listing06.32.InitOnlySetters.cs │ ├── Listing06.33.OverloadingAConstructor.cs │ ├── Listing06.34.CallingOneConstructorFromAnother.cs │ ├── Listing06.35.ProvidingAnInitializationMethod.cs │ ├── Listing06.36.ProvidingValidationOnNon-NullableProperty.cs │ ├── Listing06.37.ValidationOfNonNullReferenceTypeAutomaticallyImplementedProperties.cs │ ├── Listing06.38.RequiredProperties.cs │ ├── Listing06.39.SpecifyingRequiredMembersWithinTheObjectInitializer.cs │ ├── Listing06.40.DisablingRequiredObjectInitialization.cs │ ├── Listing06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.cs │ ├── Listing06.42.PotentialNullReturnWithMaybeNullAttribute.cs │ ├── Listing06.43.DefiningAndUsingADeconstructors.cs │ ├── Listing06.44.ImplicitlyInvokingDeconstructors.cs │ ├── Listing06.45.DeclaringAStaticField.cs │ ├── Listing06.46.AssigningAStaticFieldAtDeclaration.cs │ ├── Listing06.47.AccessingAStaticField.cs │ ├── Listing06.48.DefiningAStaticMethodOnDirectoryInfo.cs │ ├── Listing06.49.DeclaringAStaticConstructor.cs │ ├── Listing06.50.DeclaringAStaticProperty.cs │ ├── Listing06.51.DeclaringAStaticClass.cs │ ├── Listing06.52.StaticCopyMethodForDirectoryInfo.cs │ ├── Listing06.53.DeclaringAConstantField.cs │ ├── Listing06.54.DeclaringAFieldAsReadonly.cs │ ├── Listing06.55.DeclaringAReadOnlyAutomaticallyImplementedProperty.cs │ ├── Listing06.56.DefiningANestedClass.cs │ ├── Listing06.57.DefiningAPartialClass.cs │ ├── Listing06.58.DefiningANestedClassInASeperatePartialClass.cs │ └── Listing06.59.DefiningAPartialMethodToAccessItsImplementation.cs ├── Chapter07.Tests │ ├── Chapter07.Tests.csproj │ ├── Listing07.06.Tests.cs │ ├── Listing07.07.Tests.cs │ ├── Listing07.08.Tests.cs │ ├── Listing07.09.OverridingAProperty.Tests.cs │ ├── Listing07.10.RuntimeCallingTheMostDerivedImplementationOfAVirtualMethod.Tests.cs │ ├── Listing07.11.CovariantReturnTypes.Tests.cs │ ├── Listing07.12.OverrideVersusNewModifier.Tests.cs │ ├── Listing07.14.AccessingABaseMember.Tests.cs │ ├── Listing07.16.DefiningAnAbstractClass.Tests.cs │ ├── Listing07.17.DefiningAbstractMembers.Tests.cs │ ├── Listing07.18.UsingPolymorphismToListThePdaItems.Tests.cs │ ├── Listing07.20.TypeCheckingWithIsOperator.Tests.cs │ ├── Listing07.23.Tests.cs │ ├── Listing07.24.Tests.cs │ ├── Listing07.25.Tests.cs │ ├── Listing07.26.Tests.cs │ ├── Listing07.27.TuplePatternMatchingWithIsOperator.Tests.cs │ ├── Listing07.28.TuplePatternMatchingWithSwitchStatement.Tests.cs │ ├── Listing07.29.PositionalPatternMatching.Tests.cs │ ├── Listing07.30.PropertyPatternMatching.Tests.cs │ ├── Listing07.31.SwitchWithPatternMatching.Tests.cs │ ├── Listing07.32.RecursivePatternMatching.Tests.cs │ ├── Listing07.33.ListPatternMatching.Tests.cs │ └── Listing07.34.Tests.cs ├── Chapter07 │ ├── Chapter07.csproj │ ├── Listing07.01.DerivingOneClassFromAnother.cs │ ├── Listing07.02.UsingInheritedMethods.cs │ ├── Listing07.03.ClassesDerivingFromEachOtherToFormAnInheritanceChain.cs │ ├── Listing07.04.ImplicitBaseTypeCasting.cs │ ├── Listing07.05.DefiningCastOperators.cs │ ├── Listing07.06.PrivateMembersAreNotInherited.cs │ ├── Listing07.07.ProtectedMembersAreAccessibleOnlyFromDerivedClasses.cs │ ├── Listing07.08.PreventingDerivationWithSealedClasses.cs │ ├── Listing07.09.OverridingAProperty.cs │ ├── Listing07.10.RuntimeCallingTheMostDerivedImplementationOfAVirtualMethod.cs │ ├── Listing07.11.CovariantReturnTypes.cs │ ├── Listing07.12.OverrideVersusNewModifier.cs │ ├── Listing07.13.SealingMembers.cs │ ├── Listing07.14.AccessingABaseMember.cs │ ├── Listing07.15.SpecifyingWhichBaseConstructorToInvoke.cs │ ├── Listing07.16.DefiningAnAbstractClass.cs │ ├── Listing07.17.DefiningAbstractMembers.cs │ ├── Listing07.18.UsingPolymorphismToListThePdaItems.cs │ ├── Listing07.19.System.ObjectDerivationImpliedWhenNoDerivationIsSpecifiedExplicitly.cs │ ├── Listing07.20.TypeCheckingWithIsOperator.cs │ ├── Listing07.21.TypeCheckingWithSwitchStatement.cs │ ├── Listing07.22.UsingSwtichExpressionToReturnValue.cs │ ├── Listing07.23.ConstantPatternWithSwitchExpression.cs │ ├── Listing07.24.RelationalPatternWithIsOperator.cs │ ├── Listing07.25.LogicalPatternExamples.cs │ ├── Listing07.26.ParenthesizedPattern.cs │ ├── Listing07.27.TuplePatternMatchingWithIsOperator.cs │ ├── Listing07.28.TuplePatternMatchingWithSwitchStatement.cs │ ├── Listing07.29.PositionalPatternMatching.cs │ ├── Listing07.30.PropertyPatternMatching.cs │ ├── Listing07.31.SwitchWithPatternMatching.cs │ ├── Listing07.32.RecursivePatternMatching.cs │ ├── Listing07.33.ListPatternMatching.cs │ ├── Listing07.34.DataConversionUsingTheAsOperator.cs │ └── Storage.cs ├── Chapter08.Tests │ ├── Chapter08.Tests.csproj │ ├── Listing08.02.ImplementingAndUsingInterfaces.Tests.cs │ ├── Listing08.03.ImplementingAnInterface.Tests.cs │ ├── Listing08.04.CallingExplicitInterfaceMembersImplementations.Tests.cs │ ├── Listing08.07.DeclarationWithoutContainingInterface.Tests.cs │ ├── Listing08.10.InterfaceExtensionMethods.Tests.cs │ ├── Listing08.14.ForcingTheDesirableRunEncapsulation.Tests.cs │ ├── Table08.01.DefaultImplementedInterfaceMembers.Tests.cs │ └── UndersandingAccessModifiers.Tests.cs ├── Chapter08 │ ├── Chapter08.csproj │ ├── Listing08.01.DefiningAnInterface.cs │ ├── Listing08.02.ImplementingAndUsingInterfaces.cs │ ├── Listing08.03.ImplementingAnInterface.cs │ ├── Listing08.04.CallingExplicitInterfaceMemberImplementations.cs │ ├── Listing08.05.ExplicitInterfaceImplementation.cs │ ├── Listing08.06.DerivingOneInterfaceFromAnother.cs │ ├── Listing08.07.DeclarationWithoutContainingInterface.cs │ ├── Listing08.08.UsingABaseInterfaceInTheClassDeclaration.cs │ ├── Listing08.09.MultipleInterfaceInheritance.cs │ ├── Listing08.10.InterfaceExtensionMethods.cs │ ├── Listing08.11.DerivingOneInterfaceFromAnother.cs │ ├── Listing08.12.DefaultImplementedInterfaceMembers.cs │ ├── Listing08.13.CarelesslyRelyingOnAVirtualMethodImplementation.cs │ ├── Listing08.14.ForcingTheDesirableRunEncapsulation.cs │ └── Table08.01.DefaultImplementedInterfaceMembers.cs ├── Chapter09.Tests │ ├── Chapter09.Tests.csproj │ ├── Listing09.02.Tests.cs │ ├── Listing09.03.Tests.cs │ ├── Listing09.05.DeclaringRecordClass.Tests.cs │ ├── Listing09.06.EquivalentRecordClassCode.Tests.cs │ ├── Listing09.07.EquivalentRecordClassCode.Tests.cs │ ├── Listing09.09.DefiningStructsAsReadOnly.Tests.cs │ ├── Listing09.11.CloningRecordClassesWithCloneMethod.Tests.cs │ ├── Listing09.12.RecordConstructors.Tests.cs │ ├── Listing09.14.RecordDeconstructors.Tests.cs │ ├── Listing09.15.RecordDeconstructorsAndPatternMatching.Tests.cs │ ├── Listing09.16.OverridingToString.Tests.cs │ ├── Listing09.17.CustomEqualityImplementation.Tests.cs │ ├── Listing09.18.OverridingEqualsAndNotEquals.Tests.cs │ ├── Listing09.20.ImplementingValueEqualityOnACustomType.Tests.cs │ ├── Listing09.22.OverridingGetHashCodeUsingCombine.Tests.cs │ ├── Listing09.23.OverridingGetHashCodeUsingValueTuples.Tests.cs │ ├── Listing09.24.CustomizingARecord.Tests.cs │ ├── Listing09.25.SubtleBoxAndUnboxInstructions.Tests.cs │ ├── Listing09.27.SubtleBoxingIdiosyncrasies.Tests.cs │ ├── Listing09.28.AvoidingUnboxingAndCopying.Tests.cs │ ├── Listing09.33.WritingEnumValueidentifierToTraceBuffers.Tests.cs │ ├── Listing09.34.ConvertingAStringToAnEnumUsingEnum.TryParse.Tests.cs │ ├── Listing09.36.UsingBitwiseORandANDWithFlagEnums.Tests.cs │ └── Listing09.38.UsingFlagsAttribute.Tests.cs ├── Chapter09 │ ├── Chapter09.csproj │ ├── Listing09.01.ExampleStruct.cs │ ├── Listing09.02.BasicStruct.cs │ ├── Listing09.03.ProgrammingWithARecordStruct.cs │ ├── Listing09.04.EquivalentRecordStructCode.cs │ ├── Listing09.05.DeclaringRecordClass.cs │ ├── Listing09.06.EquivalentRecordClassCode.cs │ ├── Listing09.07.RecordClassInheritance.cs │ ├── Listing09.08.UsingReadOnlyModifierOnStructs.cs │ ├── Listing09.09.DefiningStructsAsReadOnly.cs │ ├── Listing09.10.CloningRecordsViaWithOperator.cs │ ├── Listing09.11.CloningRecordClassesWithCloneMethod.cs │ ├── Listing09.12.RecordConstructors.cs │ ├── Listing09.13.RecordStructInitialization.cs │ ├── Listing09.14.RecordDeconstructors.cs │ ├── Listing09.15.RecordDeconstructorsAndPatternMatching.cs │ ├── Listing09.16.OverridingToString.cs │ ├── Listing09.17.CustomEqualityImplementation.cs │ ├── Listing09.18.OverridingEqualsAndNotEquals.cs │ ├── Listing09.19.NonMatchingSignatures.cs │ ├── Listing09.20.ImplementingValueEqualityOnCustomTypes.cs │ ├── Listing09.21.ImplementStronglyTypedEquals.cs │ ├── Listing09.22.OverridingGetHashCodeUsingCombine.cs │ ├── Listing09.23.OverridingGetHashCodeUsingValueTuple.cs │ ├── Listing09.24.CustomizingARecord.cs │ ├── Listing09.25.SubtleBoxAndUnboxInstructions.cs │ ├── Listing09.26.UnboxingMustBeToTheUnderlyingType.cs │ ├── Listing09.27.SubtleBoxingIdiosyncrasies.cs │ ├── Listing09.28.AvoidingUnboxingAndCopying.cs │ ├── Listing09.29.ComparingAnIntegerSwitchToAnEnumSwitch.cs │ ├── Listing09.30.DefiningAnEnum.cs │ ├── Listing09.31.DefiningAnEnumType.cs │ ├── Listing09.32.CastingBetweenArraysOfEnums.cs │ ├── Listing09.33.WritingEnumValueIdentifierToTraceBuffer.cs │ ├── Listing09.34.ConvertingAStringToAnEnumUsingEnum.TryParse.cs │ ├── Listing09.35.UsingEnumsAsFlags.cs │ ├── Listing09.36.UsingBitwiseORandANDWithFlagEnums.cs │ ├── Listing09.37.DefiningEnumValuesforFrequentCombinations.cs │ └── Listing09.38.UsingFlagsAttribute.cs ├── Chapter10.Tests │ ├── Chapter10.Tests.csproj │ ├── CustomTestAttributes.cs │ ├── Listing10.01.ImplementingTheEqualsAndNotEqualsOperators.Tests.cs │ ├── Listing10.02.AddingAnOperator.Tests.cs │ ├── Listing10.03.CallingTheMinusAndPlusBinaryOperators.Tests.cs │ ├── Listing10.04.OverloadingTheMinusAndPlusUnaryOperators.Tests.cs │ ├── Listing10.06.ProvidingAnImplicitConversionBetweenLatitudeAndDouble.Tests.cs │ ├── Listing10.07.LeveragingADifferentLibrary.Tests.cs │ ├── Listing10.08.MakingTypesAvailableExternally.Tests.cs │ ├── Listing10.15.DefiningAFinalizer.Tests.cs │ ├── Listing10.16.ResourceCleanupWithIDisposable.Tests.cs │ └── Listing10.18.RegisteringAFinalizerWithProcessExit.Tests.cs ├── Chapter10 │ ├── Chapter10.csproj │ ├── Employee.cs │ ├── Listing10.01.ImplementingTheEqualsAndNotEqualsOperators.cs │ ├── Listing10.02.AddingAnOperator.cs │ ├── Listing10.03.CallingTheMinusAndPlusBinaryOperators.cs │ ├── Listing10.04.OverloadingTheMinusAndPlusUnaryOperators.cs │ ├── Listing10.05.TrueAndFalseOperators.cs │ ├── Listing10.06.ProvidingAnImplicitConversionBetweenLatitudeAndDouble.cs │ ├── Listing10.07.LeveragingADifferentLibrary.cs │ ├── Listing10.08.MakingTypesAvailableExternally.cs │ ├── Listing10.08.MakingTypesAvailableExternally.ps1 │ ├── Listing10.09.FileBasedNamespaces.cs │ ├── Listing10.10.DefiningANamespace.cs │ ├── Listing10.11.NestedNamespaces.cs │ ├── Listing10.12.CommentingWithXML.cs │ ├── Listing10.13.Comments.xml │ ├── Listing10.14.WeakReferences.cs │ ├── Listing10.15.DefiningAFinalizer.cs │ ├── Listing10.16.ResourceCleanupWithIDisposable.cs │ ├── Listing10.17.InvokingTheUsingStatement.cs │ ├── Listing10.18.RegisteringAFinalizerWithProcessExit.cs │ ├── Listing10.18.RegisteringAFinalizerWithProcessExit.ps1 │ ├── Listing10.19.LazyLoadingAProperty.cs │ └── Listing10.20.UsingSystem.Lazy.cs ├── Chapter11.Tests │ ├── Chapter11.Tests.csproj │ ├── Listing11.01.ThrowingAnException.Tests.cs │ ├── Listing11.06.Tests.cs │ └── Listing11.08.Tests.cs ├── Chapter11 │ ├── Chapter11.csproj │ ├── Listing11.01.ThrowingAnException.cs │ ├── Listing11.02.CatchingDifferentExceptionTypes.cs │ ├── Listing11.03.UsingExceptionDispatchInfoToRethrowException.cs │ ├── Listing11.04.CreatingCustomException.cs │ ├── Listing11.05.DefiningASerializableException.cs │ ├── Listing11.06.OverflowingAnIntegerValue.cs │ ├── Listing11.07.ACheckedBlockExample.cs │ └── Listing11.08.AnUnCheckedBlockExample.cs ├── Chapter12.Tests │ ├── Chapter12.Tests.csproj │ ├── Listing12.13.Tests.cs │ ├── Listing12.15.Tests.cs │ ├── Listing12.21.Tests.cs │ ├── Listing12.23.Tests.cs │ ├── Listing12.36.Tests.cs │ ├── Listing12.37.Tests.cs │ └── Listing12.41.Tests.cs ├── Chapter12 │ ├── Chapter12.csproj │ ├── Contact.cs │ ├── INullable.cs │ ├── Listing12.01.TheSystemCollectionsStackMethodSignatures.cs │ ├── Listing12.02.SupportingUndoInEtchASketchGame.cs │ ├── Listing12.03.DefiningASpecializedStackClass.cs │ ├── Listing12.04.DeclaringVersionsOfVariousValueTypesThatStoreNull.cs │ ├── Listing12.05.DeclaringANullableTypeThatContainsAValuePropertyOfTypeObject.cs │ ├── Listing12.06.ImplementingUndoWithAGenericStackClass.cs │ ├── Listing12.07.DeclaringAGenericClassStack.cs │ ├── Listing12.08.DeclaringAGenericInterface.cs │ ├── Listing12.09.ImplementingAGenericInterface.cs │ ├── Listing12.10.DuplicatingAnInterfaceImplementationOnASingleClass.cs │ ├── Listing12.11.DeclaringAGenericTypeConstructor.cs │ ├── Listing12.12.NotInitializingAllFieldsCasuingACompileError.cs │ ├── Listing12.13.InitializingAFieldWithTheDefaultOperator.cs │ ├── Listing12.14.DeclaringAGenericWithMultipleTypeParameters.cs │ ├── Listing12.15.UsingATypewithMultipleTypeParameters.cs │ ├── Listing12.16.UsingArityToOverloadATypeDefinition.cs │ ├── Listing12.17.ComparingSystemValueTupleInstantiationApproaches.cs │ ├── Listing12.18.NestedGenericTypes.cs │ ├── Listing12.19.DeclaringABinaryTreeClassWithNoConstraints.cs │ ├── Listing12.20.NeedingTheTypeParameterToSupportAnInterface.cs │ ├── Listing12.21.NeedingTheTypeParameterToSupportAnInterfaceOrExceptionThrown.cs │ ├── Listing12.22.DeclaringAnInterfaceConstraint.cs │ ├── Listing12.23.DeclaringABaseClassConstraint.cs │ ├── Listing12.24.DeclaringAGenericWithAMulticastDelegateConstraint.cs │ ├── Listing12.25.SpecifyingTheTypeParameterAsAValueType.cs │ ├── Listing12.26.SpecifyingMultipleConstraints.cs │ ├── Listing12.27.RequiringADefaultConstructorConstraint.cs │ ├── Listing12.28.ConstraintsCanOnlyBeSpecifiedForDefaultConstructors.cs │ ├── Listing12.29.UsingAFactoryInterfaceInPlaceOfAConstructorConstraint.cs │ ├── Listing12.30.DeclaringAnEntityToBeUsedInEntityDictionary.cs │ ├── Listing12.31.InheritedConstraintsSpecifiedExplicitly.cs │ ├── Listing12.32.RepeatingInheritedOnVirtualMembersIsProhibited.cs │ ├── Listing12.33.ConstraintExpressionsCannotRequireOperators.cs │ ├── Listing12.34.CombiningConstraintsUsingOrRelationshipNotAllowed.cs │ ├── Listing12.35.DefiningGenericMethods.cs │ ├── Listing12.36.SpecifyingTheTypeParameterExplicitly.cs │ ├── Listing12.37.InferringTheTypeParameter.cs │ ├── Listing12.38.SpecifyingConstraintsOnGenericMethods.cs │ ├── Listing12.39.BinaryTreeRequiringIComparableTypeParameters.cs │ ├── Listing12.40.ConversionBetweenGenericsWithDifferentTypeParameters.cs │ ├── Listing12.41.PreventingCovarianceMaintainsHomogeneity.cs │ ├── Listing12.42.PossibleCovariance.cs │ ├── Listing12.43.CovarianceUsingTheOutTypeParameterModifier.cs │ ├── Listing12.44.ContravarianceUsingTheInTypeParameterModifier.cs │ ├── Listing12.45.CompilerValidationOfVariance.cs │ ├── Listing12.46.StackDeclaration.cs │ ├── Listing12.47.CILCodeForStack.cs │ ├── Listing12.48.CILWithExclamationPointNotation.cs │ ├── Listing12.49.StackIntDefinition.cs │ └── Listing12.50.DeclaringVariablesOfTypeStack.cs ├── Chapter13.Tests │ ├── Chapter13.Tests.csproj │ ├── Listing13.08.Tests.cs │ ├── Listing13.11.UsingADifferentComparisonHandlerCompatibleMethod.Tests.cs │ ├── Listing13.12.Tests.cs │ ├── Listing13.13.Tests.cs │ ├── Listing13.15.Tests.cs │ ├── Listing13.16.Tests.cs │ ├── Listing13.17.Tests.cs │ ├── Listing13.18.Tests.cs │ ├── Listing13.19.Tests.cs │ ├── Listing13.20.UsingAnOuterVariableInALambdaExpression.Tests.cs │ ├── Listing13.21.StaticAnonymousFunctions.Tests.cs │ ├── Listing13.22.CSharpEquivalentOfCILCodeGeneratedByCompilerForOuterVariables.Tests.cs │ ├── Listing13.23.CapturingLoopVariablesCSharpFive.Tests.cs │ ├── Listing13.24.LoopVariableWorkaroundBeforeCSharpFive.Tests.cs │ ├── Listing13.26.ExamingingAnExpressionTree.Tests.cs │ └── Table13.01.Tests.cs ├── Chapter13 │ ├── 13.7.sequencediagram │ ├── 13.7.sequencediagram.layout │ ├── Chapter13.csproj │ ├── Listing13.01.BubbleSortMethod.cs │ ├── Listing13.02.BubbleSortMethodAscendingOrDescending.cs │ ├── Listing13.03.BubbleSortMethodWithDelegateParameter.cs │ ├── Listing13.04.FuncAndActionDelegateDeclarations.cs │ ├── Listing13.05.DeclaringADelegateType.cs │ ├── Listing13.06.DeclaringANestedDelegateType.cs │ ├── Listing13.07.DeclaringAFuncCompatibleMethod.cs │ ├── Listing13.08.UsingMethodNameAsArgument.cs │ ├── Listing13.09.PassingADelegateAsAParameterInCSharp.cs │ ├── Listing13.10.SystemDelegateCannotBeBaseClass.cs │ ├── Listing13.11.UsingADifferentFuncCompatibleMethod.cs │ ├── Listing13.12.CreatingDelegateWithStatementLambda.cs │ ├── Listing13.13.OmittingParameterTypesFromStatementLambdas.cs │ ├── Listing13.14.StatementLambdasWithASingleInputParameter.cs │ ├── Listing13.15.ParameterlessStatementLambdas.cs │ ├── Listing13.16.PassingADelegateWithAnExpressionLambda.cs │ ├── Listing13.17.PassingAnAnonymousMethodInCSharpTwo.cs │ ├── Listing13.18.UsingVarianceForDelegates.cs │ ├── Listing13.19.CSharpEquivalentOfCILGeneratedByTheCompilerForLambdaExpressions.cs │ ├── Listing13.20.UsingAnOuterVariableInALambdaExpression.cs │ ├── Listing13.21.StaticAnonymousFunctions.cs │ ├── Listing13.22.CSharpEquivalentOfCILCodeGeneratedByCompilerForOuterVariables.cs │ ├── Listing13.23.CapturingLoopVariablesCSharpFive.cs │ ├── Listing13.24.LoopVariableWorkaroundBeforeCSharpFive.cs │ ├── Listing13.25.ConvertingExpressionTreeToSqlWhereClause.cs │ ├── Listing13.26.ExamingingAnExpressionTree.cs │ ├── Program_Main.sequencediagram │ ├── Program_Main.sequencediagram.layout │ ├── Program_Main_1.sequencediagram │ ├── Program_Main_1.sequencediagram.layout │ ├── Program_Main_2.sequencediagram │ ├── Program_Main_2.sequencediagram.layout │ ├── Table13.01.a.LambdaExpressionNotesAndExamples.cs │ ├── Table13.01.b.LambdaExpressionNotesAndExamples.cs │ ├── Table13.01.c.LambdaExpressionNotesAndExamples.cs │ ├── Table13.01.d.LambdaExpressionNotesAndExamples.cs │ ├── Table13.01.e.LambdaExpressionNotesAndExamples.cs │ ├── Table13.01.f.LambdaExpressionNotesAndExamples.cs │ ├── Table13.01.g.LambdaExpressionNotesAndExamples.cs │ ├── Table13.01.h.LambdaExpressionNotesAndExamples.cs │ ├── Table13.01.i.LambdaExpressionNotesAndExamples.cs │ └── Table13.01.j.LambdaExpressionNotesAndExamples.cs ├── Chapter14.Tests │ ├── Chapter14.Tests.csproj │ ├── Listing14.03.ConnectingThePublisherAndSubscribers.Tests.cs │ ├── Listing14.04.InvokingADelegateWithoutCheckingForNull.Tests.cs │ ├── Listing14.06.UsingthePlusEqualsAndMinusEqualsDelegateOperators.Tests.cs │ ├── Listing14.07.UsingThePlusAndMinusDelegateOperators.Tests.cs │ ├── Listing14.08.OnTemperatureChangedThrowingAnException.Tests.cs │ ├── Listing14.09.HandlingExceptionsFromSubscribers.Tests.cs │ ├── Listing14.10.UsingTheAssignmentOperationRatherThanPlusEquals.Tests.cs │ └── Listing14.17.CustomAddAndRemoveHandlers.Tests.cs ├── Chapter14 │ ├── Chapter14.csproj │ ├── Listing14.01.HeaterAndCoolerEventSubscriberImplementations.cs │ ├── Listing14.02.DefiningTheEventPublsherThermostat.cs │ ├── Listing14.03.ConnectingThePublisherAndSubscribers.cs │ ├── Listing14.04.ConnectingThePublisherAndSubscribers.Placeholder.cs │ ├── Listing14.04.InvokingADelegateWithoutCheckingForNull.cs │ ├── Listing14.05.InvokingADelegate.cs │ ├── Listing14.06.UsingthePlusEqualsAndMinusEqualsDelegateOperators.cs │ ├── Listing14.07.UsingThePlusAndMinusDelegateOperators.cs │ ├── Listing14.08.OnTemperatureChangedThrowingAnException.cs │ ├── Listing14.09.HandlingExceptionsFromSubscribers.cs │ ├── Listing14.10.UsingTheAssignmentOperationRatherThanPlusEquals.cs │ ├── Listing14.11.FiringTheEventFromOutsideTheEventContainer.cs │ ├── Listing14.12.UsingTheEventKeywordWithTheEventCodingPattern.cs │ ├── Listing14.13.DeclaringAGenericDelegateType.cs │ ├── Listing14.14.FiringTheEventNotification.cs │ ├── Listing14.15.DeclaringTheOnTemperatureChangeEvent.cs │ ├── Listing14.16.CSharpConceptualEquivalentOfEventCILCode.cs │ └── Listing14.17.CustomAddAndRemoveHandlers.cs ├── Chapter15.Tests │ ├── Chapter15.Tests.csproj │ ├── Listing15.01.Tests.cs │ ├── Listing15.02.DictionaryInitializers.Tests.cs │ ├── Listing15.03.Tests.cs │ ├── Listing15.04.Tests.cs │ ├── Listing15.06.Tests.cs │ ├── Listing15.07.Tests.cs │ ├── Listing15.08.Tests.cs │ ├── Listing15.09.Tests.cs │ ├── Listing15.10.FilteringWithSystem.Linq.Enumerable.Where.Tests.cs │ ├── Listing15.11.Tests.cs │ ├── Listing15.12.ProjectionWithSystem.Linq.Enumerable.Select.Tests.cs │ ├── Listing15.13.ProjectionToTuple.Tests.cs │ ├── Listing15.14.ExecutingLinqQueriesInParallel.Tests.cs │ ├── Listing15.15.Tests.cs │ ├── Listing15.16.Tests.cs │ ├── Listing15.17.Tests.cs │ ├── Listing15.18.Tests.cs │ ├── Listing15.19.AnInnerJoinUsingSystem.Linq.Enumerable.Join.Tests.cs │ ├── Listing15.20.AnotherInnerJoinWithSystem.Linq.Enumerable.Join.Tests.cs │ ├── Listing15.21.Tests.cs │ ├── Listing15.22.CreatingAChildCollectionWithSystem.Linq.Enumerable.GroupJoin.Tests.cs │ ├── Listing15.23.Tests.cs │ ├── Listing15.24.CallingSelectMany.Tests.cs │ ├── Listing15.25.MoreSystem.Linq.EnumerableMethodCalls.Tests.cs │ ├── Listing15.26.ImplicitLocalVariablesWithAnonymousTypes.Tests.cs │ ├── Listing15.27.ProjectionToAnAnonymousType.Tests.cs │ └── Listing15.29.Tests.cs ├── Chapter15 │ ├── Chapter15.csproj │ ├── EmployeeData.cs │ ├── Listing15.01.CollectionInitialization.cs │ ├── Listing15.02.DictionaryInitializers.cs │ ├── Listing15.03.ForeachWithArrays.cs │ ├── Listing15.04.CompiledImplementationOfForeachWithArrays.cs │ ├── Listing15.05.IteratingOverACollectionUsingWhile.cs │ ├── Listing15.06.ASeparateEnumeratorMaintainingStateDuringAnIteration.cs │ ├── Listing15.07.CompiledResultOfForeachOnCollections.cs │ ├── Listing15.08.ErrorHandlingAndResourceCleanupWithUsing.cs │ ├── Listing15.09.SampleClassesForUseWithStandardQueryOperators.cs │ ├── Listing15.10.FilteringWithSystem.Linq.Enumerable.Where.cs │ ├── Listing15.11.ProjectionWithSystem.Linq.Enumerable.Select.cs │ ├── Listing15.12.ProjectionWithSystem.Linq.Enumerable.Select.cs │ ├── Listing15.13.ProjectionToATuple.cs │ ├── Listing15.14.ExecutingLinqQueriesInParallel.cs │ ├── Listing15.15.CountingItemsWithCount.cs │ ├── Listing15.16.FilteringWithSystem.Linq.Enumerable.Where.cs │ ├── Listing15.17.OrderingWithSystem.Linq.Enumerable.OrderByAndThenBy.cs │ ├── Listing15.18.SampleEmployeeAndDepartmentData.cs │ ├── Listing15.19.AnInnerJoinUsingSystem.Linq.Enumerable.Join.cs │ ├── Listing15.20.AnotherInnerJoinWithSystem.Linq.Enumerable.Join.cs │ ├── Listing15.21.GroupingItemsTogetherUsingSystem.Linq.Enumerable.GroupBy.cs │ ├── Listing15.22.CreatingAChildCollectionWithSystem.Linq.Enumerable.GroupJoin.cs │ ├── Listing15.23.ImplementingAnOuterJoinUsingGroupJoinWithSelectMany.cs │ ├── Listing15.24.CallingSelectMany.cs │ ├── Listing15.25.MoreSystem.Linq.EnumerableMethodCalls.cs │ ├── Listing15.26.ImplicitLocalVariablesWithAnonymousTypes.cs │ ├── Listing15.27.ProjectionToAnAnonymousType.cs │ ├── Listing15.28.TypeSafetyAndImmutabilityOfAnonymousTypes.cs │ ├── Listing15.29.InitializingAnonymousTypeArrays.cs │ └── PatentData.cs ├── Chapter16.Tests │ ├── Chapter16.Tests.csproj │ ├── Listing16.01.Tests.cs │ ├── Listing16.03.Tests.cs │ ├── Listing16.04.Tests.cs │ ├── Listing16.05.Tests.cs │ ├── Listing16.07.SortingUsingAQueryExpressionWithAnOrderbyClause.Tests.cs │ ├── Listing16.08.ProjectingAFileInfoCollectionAndSortingByFileSize.Tests.cs │ ├── Listing16.10.Tests.cs │ ├── Listing16.11.Tests.cs │ ├── Listing16.12.Tests.cs │ ├── Listing16.13.Tests.cs │ ├── Listing16.14.Tests.cs │ ├── Listing16.15.Tests.cs │ ├── Listing16.17.Tests.cs │ └── Listing16.CSharpExpectedData.cs ├── Chapter16 │ ├── Chapter16.csproj │ ├── Listing16.01.SimpleQueryExpression.cs │ ├── Listing16.02.ProjectingUsingQueryExpressions.cs │ ├── Listing16.03.TuplesWithinQueryExpressions.cs │ ├── Listing16.04.DeferredExecutionAndQueryExpressions1.cs │ ├── Listing16.05.DeferredExecutionAndQueryExpressions2.cs │ ├── Listing16.06.AnonymousTypesWithinQueryExpressions.cs │ ├── Listing16.07.SortingUsingAQueryExpressionWithAnOrderbyClause.cs │ ├── Listing16.08.ProjectingAFileInfoCollectionAndSortingByFileSize.cs │ ├── Listing16.09.OrderingTheResultsInAQueryExpression.cs │ ├── Listing16.10.GroupingTogetherQueryResults.cs │ ├── Listing16.11.SelectingTupleFollowingTheGroupbyClause.cs │ ├── Listing16.12.SelectingWithoutTheQueryContinuation.cs │ ├── Listing16.13.MultipleSelection.cs │ ├── Listing16.14.CartesianProduct.cs │ ├── Listing16.15.ObtainingDistinctMembersFromAQueryExpression.cs │ ├── Listing16.16.SimpleQueryExpression.cs │ └── Listing16.17.StandardQueryOperatorSyntax.cs ├── Chapter17.Tests │ ├── Chapter17.Tests.csproj │ ├── Listing17.01.UsingList.Tests.cs │ ├── Listing17.02.Tests.cs │ ├── Listing17.03.Tests.cs │ ├── Listing17.04.Tests.cs │ ├── Listing17.05.Tests.cs │ ├── Listing17.06.Tests.cs │ ├── Listing17.07.IteratingOverDictionaryWithForeach.Tests.cs │ ├── Listing17.09.SlicingWithSpan.Tests.cs │ ├── Listing17.12.DefiningAnIndexOperatorWithVariableParameters.Tests.cs │ ├── Listing17.14.YieldingTheCSharpKeywordsSequentially.Tests.cs │ ├── Listing17.16.UsingPair.GetEnumeratorViaForeach.Tests.cs │ ├── Listing17.18.UsingForeachWithBinaryTree.Tests.cs │ └── Listing17.21.UsingYieldReturnInAMethodThatReturnsIEnumberable.Tests.cs ├── Chapter17 │ ├── Chapter17.csproj │ ├── Listing17.01.UsingList.cs │ ├── Listing17.02.ImplementingIComparer.cs │ ├── Listing17.03.UsingTheBitComplementOfTheBinarySearchResult.cs │ ├── Listing17.04.DemonstratingFindAllAndItsPredicateParameter.cs │ ├── Listing17.05.AddingItemsToADictionary.cs │ ├── Listing17.06.InsertingItemsInADictionaryUsingTheIndexOperator.cs │ ├── Listing17.07.IteratingOverDictionaryWithForeach.cs │ ├── Listing17.07a.IteratingOverSortedDictionaryWithForeach.Placeholder.cs │ ├── Listing17.08.ImplementingIEqualityComparer.cs │ ├── Listing17.09.SlicingWithSpan.cs │ ├── Listing17.10.DefiningAnIndexer.cs │ ├── Listing17.11.ChangingTheIndexersDefaultName.cs │ ├── Listing17.12.DefiningAnIndexOperatorWithVariableParameters.cs │ ├── Listing17.13.IteratorInterfacesPattern.cs │ ├── Listing17.14.YieldingTheCSharpKeywordsSequentially.cs │ ├── Listing17.15.UsingYieldToImplementBinaryTree.cs │ ├── Listing17.16.UsingPair.GetEnumeratorViaForeach.cs │ ├── Listing17.17.PlacingYieldReturnStatementsWithinALoop.cs │ ├── Listing17.18.UsingForeachWithBinaryTree.cs │ ├── Listing17.19.EscapingIterationViaYieldBreak.cs │ ├── Listing17.20.CSharpEquivalentOfCompilerGeneratedCodeForIterators.cs │ └── Listing17.21.UsingYieldReturnInAMethodThatReturnsIEnumberable.cs ├── Chapter18.Tests │ ├── Chapter18.Tests.csproj │ ├── Listing18.03.Tests.cs │ ├── Listing18.05.Tests.cs │ ├── Listing18.06.Tests.cs │ ├── Listing18.07.LeveragingNameofWithINotifyPropertyChanged.Tests.cs │ ├── Listing18.16.RetrievingASpecificAttributeAndCheckingItsInitialization.Tests.cs │ ├── Listing18.24.UsingConditionalAttributeToEliminateACall.Tests.cs │ ├── Listing18.26.GenericException.Tests.cs │ ├── Listing18.27.CallerArgumentExpression.Tests.cs │ ├── Listing18.28.Tests.cs │ ├── Listing18.29.DynamicProgrammingUsingReflection.Tests.cs │ ├── Listing18.30.RuntimeBindingToXMLElementsWithoutDynamic.Tests.cs │ └── Listing18.31.RuntimeBindingToXMLWithDynamics.Tests.cs ├── Chapter18 │ ├── 4.0 │ │ ├── Listing18.01.StartingMethodInSeparateThread.cs │ │ ├── Listing18.01.StartingMethodInSeparateThread.cs.encrypt │ │ ├── Listing18.02.ReturningAResultFromTask.cs │ │ ├── Listing18.02.ReturningAResultFromTask.cs.encrypt │ │ ├── Listing18.03.RegisteringForNotifactionsWithContinueWith.cs │ │ ├── Listing18.03.RegisteringForNotifactionsWithContinueWith.cs.encrypt │ │ ├── Listing18.05.UnhandledExceptionsUsingContinueWith.cs │ │ ├── Listing18.05.UnhandledExceptionsUsingContinueWith.cs.encrypt │ │ ├── Listing18.06.CancelingATaskUsingCancellationToken.cs │ │ ├── Listing18.08.LoopSynchronouslyCalculatingPiInSections.cs │ │ ├── Listing18.09.StartingMethodInSeparateThread.cs │ │ ├── Listing18.10.ParallelExecutionOfAForeachLoop.cs │ │ ├── Listing18.11.UnhandledExceptionHandlingForParallelIterations.cs │ │ ├── Listing18.12.CancelingAParallelLoop.cs │ │ ├── Listing18.12.CancelingAParallelLoop.cs.encrypt │ │ ├── Listing18.13.LinqSelect.cs │ │ ├── Listing18.13.LinqSelect.cs.encrypt │ │ ├── Listing18.14.ParallelLinqSelect.cs │ │ ├── Listing18.14.ParallelLinqSelect.cs.encrypt │ │ ├── Listing18.15.ParallelLinqWithStandardQueryOperators.cs │ │ ├── Listing18.15.ParallelLinqWithStandardQueryOperators.cs.encrypt │ │ ├── Listing18.16.ParallelLinqWithQueryExpressions.cs │ │ ├── Listing18.16.ParallelLinqWithQueryExpressions.cs.encrypt │ │ ├── Listing18.18.StartingMethodUsingThread.cs │ │ ├── Listing18.18.StartingMethodUsingThread.cs.encrypt │ │ ├── Listing18.19.AynchronousCallsUsingThreadPool.cs │ │ ├── Listing18.19.AynchronousCallsUsingThreadPool.cs.encrypt │ │ ├── Listing18.20.RegisteringForUnhandledExceptions.cs │ │ └── Listing18.20.RegisteringForUnhandledExceptions.cs.encrypt │ ├── Chapter18.csproj │ ├── Listing18.01.UsingTypeGetPropertiesToObtainAnObjectsPublicProperties.cs │ ├── Listing18.02.UsingTypeofToCreateASystem.TypeInstance.cs │ ├── Listing18.03.DynamicallyInvokingAMember.cs │ ├── Listing18.04.DeclaringTheStackClass.cs │ ├── Listing18.05.ReflectionWithGenerics.cs │ ├── Listing18.06.UsingReflectionWithGenericTypes.cs │ ├── Listing18.07.DynamicallyInvokingAMember.cs │ ├── Listing18.08.DecoratingAPropertyWithAnAttribute.cs │ ├── Listing18.09.DecoratingAPropertyWithMultipleAttributes.cs │ ├── Listing18.10.AssemblyAttributesWithinAssemblyInfo.cs │ ├── Listing18.11.SpecifyingAReturnAttribute.cs │ ├── Listing18.12.csproj.xml │ ├── Listing18.12.csprojMockFileForResequencingListings.Placeholder.cs │ ├── Listing18.13.DefiningACustomAttribute.cs │ ├── Listing18.14.RetrievingACustomAttribute.cs │ ├── Listing18.15.ProvidingAnAttributeConstructor.cs │ ├── Listing18.16.RetrievingASpecificAttributeAndCheckingItsInitialization.cs │ ├── Listing18.17.RetrievingCustomAttributeInstances.cs │ ├── Listing18.18.UpdatingCommandLineHandler.TryParseToHandleAliases.cs │ ├── Listing18.19.RestrictingTheConstructsAnAttributeCanDecorate.cs │ ├── Listing18.20.AttributeUsageAttributeRestrictingWhereToApplyAnAttribute.cs │ ├── Listing18.21.LimitingAnAttributesUsageWithAttributeUsageAttribute.cs │ ├── Listing18.22.UsingANamedParameter.cs │ ├── Listing18.23.UsingFlagsAttribute.cs │ ├── Listing18.24.UsingConditionalAttributeToEliminateACall.cs │ ├── Listing18.25.UsingObsoleteAttribute.cs │ ├── Listing18.26.GenericException.cs │ ├── Listing18.27.CallerArgumentExpression.cs │ ├── Listing18.28.InvokingCallerAttributesMethod.cs │ ├── Listing18.29.DynamicProgrammingUsingReflection.cs │ ├── Listing18.30.RuntimeBindingToXMLElementsWithoutDynamic.cs │ ├── Listing18.31.RuntimeBindingToXMLWithDynamics.cs │ ├── Listing18.32.ImplementingACustomDynamicObject.cs │ └── Listing18.33.OverridableMembersOnSystem.Dynamic.DynamicObject.cs ├── Chapter19.Tests │ ├── Chapter19.Tests.csproj │ ├── Listing19.03.Test.cs │ ├── Listing19.04.Test.cs │ ├── Listing19.05.Tests.cs │ ├── Listing19.06.Tests.cs │ ├── Listing19.07.Tests.cs │ └── SharedProgram.Tests.cs ├── Chapter19 │ ├── Chapter19.csproj │ ├── Listing19.01.InvokingAnAsynchronousTask.cs │ ├── Listing19.02.PollingATask.cs │ ├── Listing19.03.CallingTaskContinueWith.cs │ ├── Listing19.04.RegisteringForNotificationsWithContinueWith.cs │ ├── Listing19.05.HandlingATasksUnhandledException.cs │ ├── Listing19.06.ObservingUnhandledExceptionsWithContinueWith.cs │ ├── Listing19.07.RegisteringForUnhandledExceptions.cs │ ├── Listing19.08.CancelingTaskUsingCancellationToken.cs │ ├── Listing19.09.UsingTaskRun.cs │ ├── Listing19.10.CooperativeLongRunningTasks.cs │ └── Utility.cs ├── Chapter20.Tests │ ├── BaseProgramTests.cs │ ├── Chapter20.Tests.csproj │ ├── CryptographerTests.cs │ ├── Listing20.01.Tests.cs │ ├── Listing20.02.Tests.cs │ ├── Listing20.03.Tests.cs │ ├── Listing20.04.Tests.cs │ ├── Listing20.06.AsynchronousStreams.Tests.cs │ ├── Listing20.07.Tests.cs │ ├── Listing20.09.ImplementingCustomAsynchronousMethod.Tests.cs │ └── ProgramWrapper.cs ├── Chapter20 │ ├── Chapter20.csproj │ ├── IAsyncEnumerable.cd │ ├── Listing20.01.SynchronousWebRequestHighLatency.cs │ ├── Listing20.02.AsynchronousWebRequest.cs │ ├── Listing20.03.AsynchronousHighLatencyUsingTaskAsynchronyPattern.cs │ ├── Listing20.04.ValueTaskAsyncReturn.cs │ ├── Listing20.05.AwaitStatement.cs │ ├── Listing20.06.AsynchronousStreams.cs │ ├── Listing20.07.AsynchronousStreamsInvocationWithAwaitForeach.cs │ ├── Listing20.08.SignaturesOfAsyncEnumerableSelectMethods.cs │ ├── Listing20.09.CatchingExceptionFromAsyncVoidMethod.cs │ ├── Listing20.10.AsynchronousAsALambda.cs │ ├── Listing20.11.ImplementingCustomAsynchronousMethod.cs │ ├── Listing20.12.CustomMethodWithProgressSupport.cs │ ├── Listing20.13.CallingTaskContinueWith.cs │ ├── Listing20.14.SynchronousHighLatencyInvocationInWPF.cs │ ├── Listing20.15.SynchronousHighLatencyInvocationInWPFUsingAwait.cs │ └── Listing20.16.IteratingOverAwaitOperation.cs ├── Chapter21.Tests │ ├── Chapter21.Tests.csproj │ ├── Listing21.01.Tests.cs │ ├── Listing21.02.Tests.cs │ ├── Listing21.03.ParallelForeachLoop.Tests.cs │ └── Listing21.04.Tests.cs ├── Chapter21 │ ├── Chapter21.csproj │ ├── Listing21.01.SynchronousPiSections.cs │ ├── Listing21.02.ParallelPiCalculation.cs │ ├── Listing21.03.ParallelForeachLoop.cs │ ├── Listing21.04.UnhandledExceptionsParallelIterations.cs │ ├── Listing21.05.CancelingParallelLoop.cs │ ├── Listing21.06.LinqSelect.cs │ ├── Listing21.07.ParallelLinqSelect.cs │ ├── Listing21.08.ParallelLinqStandardQueryOperators.cs │ ├── Listing21.09.ParallelLinqQueryExpressions.cs │ ├── Listing21.10.CancelingParallelLoop.cs │ └── Utility.cs ├── Chapter22.Tests │ ├── Chapter22.Tests.csproj │ ├── Listing22.01.UnsychronizedState.Tests.cs │ ├── Listing22.02.UnsychronizedLocalVariables.Tests.cs │ ├── Listing22.03.SynchronizingWithMonitor.Tests.cs │ ├── Listing22.04.SynchronizingWithLockKeyword.Tests.cs │ ├── Listing22.05.AsyncMain.Tests.cs │ ├── Listing22.09.Tests.cs │ ├── Listing22.10.Tests.cs │ ├── Listing22.11.Tests.cs │ └── Listing22.12.Tests.cs ├── Chapter22 │ ├── Chapter22.csproj │ ├── Listing22.01.UnsychronizedState.cs │ ├── Listing22.02.UnsychronizedLocalVariables.cs │ ├── Listing22.03.SynchronizingWithMonitor.cs │ ├── Listing22.04.SynchronizingWithLockKeyword.cs │ ├── Listing22.05.AsyncMain.cs │ ├── Listing22.06.SynchronizingUsingInterlocked.cs │ ├── Listing22.07.FiringEventNotification.cs │ ├── Listing22.08.ThreadSafeEventNotification.cs │ ├── Listing22.09.CreatingASingleInstanceApplication.cs │ ├── Listing22.10.WaitingForManualResetEventSlim.cs │ ├── Listing22.11.UsingThreadLocalForThreadLocalStorage.cs │ ├── Listing22.12.UsingThreadStaticAttribute.cs │ ├── Listing22.13.TaskDelayAsTimer.cs │ └── PiCalculation.cs ├── Chapter23.Tests │ ├── Chapter23.Tests.csproj │ ├── Listing23.17.Tests.cs │ ├── Listing23.18.Tests.cs │ ├── Listing23.19.Tests.cs │ └── Listing23.20.DesignatingABlockForUnsafeCode.Tests.cs ├── Chapter23 │ ├── App.config │ ├── Chapter23.csproj │ ├── Listing23.01.DeclaringAnExternalMethod.cs │ ├── Listing23.02.TheVirtualAllocExAPI.cs │ ├── Listing23.03.DeclaringTheVirtualAllocExAPI.cs │ ├── Listing23.04.UsingrefAndoutRatherThanPointers.cs │ ├── Listing23.05.DeclaringTypesFromUnmanagedStructs.cs │ ├── Listing23.06.Win32ErrorHandling.cs │ ├── Listing23.07.ManagedResourcesUsingSafeHandle.cs │ ├── Listing23.08.EncapsulatingTheAPIsTogether.cs │ ├── Listing23.09.WrappingTheUnderlyingAPI.cs │ ├── Listing23.10.DesignatingAMethodForUnsafeCode.cs │ ├── Listing23.11.DesignatingACodeBlockForUnsafeCode.cs │ ├── Listing23.12.InvalidReferentTypeExample.xml │ ├── Listing23.13.InvalidReferentTypeExample.cs │ ├── Listing23.14.FixedStatement.cs │ ├── Listing23.15.AfixedStatementWithoutAddressOrArrayIndexer.cs │ ├── Listing23.16.AllocatingDataOnTheCallStack.cs │ ├── Listing23.17.ModifyingAnImmutableString.cs │ ├── Listing23.18.ModifyingAnImmutableWithTheIndexOperatorInUnsafeCode.cs │ ├── Listing23.19.DirectlyAccessingAReferentTypesMembers.cs │ ├── Listing23.20.DesignatingABlockForUnsafeCode.cs │ └── Program.cs ├── ChapterTests.props ├── Modelling │ ├── 13.7.sequencediagram │ ├── 13.7.sequencediagram.layout │ ├── ModelDefinition │ │ └── Modelling.uml │ └── Modelling.modelproj └── Shared │ ├── AsyncCompletedEventArgs.cs │ ├── Cryptographer.cs │ ├── DoWorkEventArgs.cs │ ├── Lib │ └── IntelliTect.TestTools.Console.dll │ ├── NetCore.cs │ ├── PiCalculator+InternalPiDigitCalculator.cs │ ├── PiCalculator.cs │ ├── Program.cs │ └── Tests │ ├── CompilerAssert.cs │ ├── Parallel.runsettings │ └── PowerShellTestUtilities.cs └── testEnvironments.json /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=auto 3 | 4 | # Explicitly declare text files you want to always be normalized and converted 5 | # to native line endings on checkout. 6 | *.cs text 7 | *.csproj text 8 | *.props text 9 | *.targets text 10 | 11 | # Declare files that will always have CRLF line endings on checkout. 12 | *.sln text eol=crlf 13 | 14 | # Denote all files that are truly binary and should not be modified. 15 | *.png binary 16 | *.jpg binary -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: true 2 | contact_links: 3 | - name: Essential C Sharp Disscussions 4 | url: https://github.com/IntelliTect/EssentialCSharp/discussions 5 | about: For questions and feedback, please use discussions. 6 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Summary 2 | 3 | Describe your changes here. 4 | 5 | Fixes #Issue_Number (if available) 6 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "nuget" # See documentation for possible values 4 | directory: "/" # Location of package manifests 5 | schedule: 6 | interval: "weekly" 7 | groups: 8 | microsoft-codeanalysis: 9 | patterns: 10 | - "Microsoft.CodeAnalysis*" 11 | 12 | - package-ecosystem: "github-actions" # See documentation for possible values 13 | directory: "/" # Location of package manifests 14 | schedule: 15 | interval: "weekly" 16 | -------------------------------------------------------------------------------- /.runsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 6 | 7 | 15 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "streetsidesoftware.code-spell-checker", 4 | ] 5 | } -------------------------------------------------------------------------------- /Common.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0;net7.0;net6.0 4 | 5 | -------------------------------------------------------------------------------- /Project.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | } 6 | ], 7 | "settings": {} 8 | } -------------------------------------------------------------------------------- /RenumberListingsInformation.txt: -------------------------------------------------------------------------------- 1 | Checkout: 2 | https://github.com/IntelliTect/ListingManager -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | * Ensure all files are UTF8 2 | -------------------------------------------------------------------------------- /Utilities/SetProjectRenameAlias.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntelliTect/EssentialCSharp/af6e8da6480032e00fb55273a4c736be85086777/Utilities/SetProjectRenameAlias.ps1 -------------------------------------------------------------------------------- /after.EssentialCSharp.sln.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | PowerShell.exe -noprofile -nologo -file %~dp0%~n0.ps1 -------------------------------------------------------------------------------- /dotnet-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | > Test.Results.txt 3 | if [ ${BASH_VERSION:0:1} -lt 4 ] 4 | then 5 | shopt -s 6 | projPath=./src/**/*.Test*.csproj 7 | else 8 | shopt -s globstar 9 | projPath=**/*.Test*.csproj 10 | fi 11 | for csproj in $projPath 12 | do 13 | echo $xls 14 | dotnet test "$csproj" | tee -a Test.Results.txt 15 | done -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "8.0.0", 4 | "rollForward": "latestFeature", 5 | "allowPrerelease": true 6 | } 7 | } -------------------------------------------------------------------------------- /src/Chapter.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | AddisonWesley.Michaelis.EssentialCSharp.Shared.Program 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/Chapter01.Tests/Listing01.03.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_03.Tests; 3 | 4 | [TestClass] 5 | public class HelloWorldTests 6 | { 7 | [TestMethod] 8 | public void Main_UpDown() 9 | { 10 | const string expected = 11 | @"Up 12 | Down"; 13 | 14 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 15 | expected, HelloWorld.Main); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter01.Tests/Listing01.04.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_04.Tests; 3 | 4 | [TestClass] 5 | public class HelloWorldTests 6 | { 7 | [TestMethod] 8 | public void Main_InigoHello() 9 | { 10 | const string expected = 11 | @"Down 12 | Side 13 | Up"; 14 | 15 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 16 | expected, HelloWorld.Main); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Chapter01.Tests/Listing01.05.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_05.Tests; 3 | 4 | [TestClass] 5 | public class HelloWorldTests 6 | { 7 | [TestMethod] 8 | public void Main_InigoHello() 9 | { 10 | const string expected = 11 | @"Hello. My name is Inigo Montoya."; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, HelloWorld.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter01.Tests/Listing01.06.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_06.Tests; 3 | 4 | [TestClass] 5 | public class HelloWorldTests 6 | { 7 | [TestMethod] 8 | public void Main_InigoHello() 9 | { 10 | const string expected = 11 | @"Hello. My name is Inigo Montoya."; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter01.Tests/Listing01.08.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_08.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_InigoHello() 9 | { 10 | const string expected = @"Hello, My name is Inigo Montoya"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter01.Tests/Listing01.09.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_09.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_GiveNone_GetZero() 9 | { 10 | int expected = 0; 11 | int value = Program.Main(Array.Empty()); 12 | 13 | Assert.AreEqual(expected, value); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter01.Tests/Listing01.10.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_10.Tests; 3 | 4 | [TestClass] 5 | public class HelloWorldTests 6 | { 7 | [TestMethod] 8 | public void Main_HelloToInigo() 9 | { 10 | const string expected = @"Hello Inigo Montoya"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, HelloWorld.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter01.Tests/Listing01.11.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_11.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_HelloToInigo() 9 | { 10 | const string expected = @"Hello Inigo Montoya"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, HelloWorld.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter01.Tests/Listing01.12.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_12.Tests; 3 | 4 | [TestClass] 5 | public class MiracleMaxTests 6 | { 7 | [TestMethod] 8 | public void Main_StormCastleShort() 9 | { 10 | const string expected = @"Have fun storming the castle!"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, MiracleMax.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter01.Tests/Listing01.13.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_13.Tests; 3 | 4 | [TestClass] 5 | public class HelloWorldTests 6 | { 7 | [TestMethod] 8 | public void Main_InigoMantra_ProperOutput() 9 | { 10 | const string expected = 11 | @"My name is Inigo Montoya. 12 | You killed my father...."; 13 | 14 | IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, HelloWorld.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter01.Tests/Listing01.14.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_14.Tests; 3 | 4 | [TestClass] 5 | public class MiracleMaxTests 6 | { 7 | [TestMethod] 8 | public void Main_StormCastleLong() 9 | { 10 | const string expected = 11 | @"Have fun storming the castle! 12 | Think it will work? 13 | It would take a miracle."; 14 | 15 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 16 | expected, StormingTheCastle.Main); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Chapter01.Tests/Listing01.15.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_15.Tests; 3 | 4 | [TestClass] 5 | public class Listing01_13_Tests 6 | { 7 | [TestMethod] 8 | public void Main_ItWouldTakeAMiracle_OutputWrittenToConsole() 9 | { 10 | const string expected = 11 | @"It would take a miracle."; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, StormingTheCastle.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter01.Tests/Listing01.16.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_16.Tests; 3 | 4 | [TestClass] 5 | public class HeyYouTests 6 | { 7 | [TestMethod] 8 | public void Main_InputInigoMontoya_WriteNothing() 9 | { 10 | const string expected = 11 | @"Hey you! 12 | Enter your first name: <>Enter your last name: <>"; 15 | 16 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 17 | expected, HeyYou.Main); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Chapter01.Tests/Listing01.17.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_17.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_InputOne_WriteOne() 9 | { 10 | const string expected = @"1<<1>>"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter01/Listing01.01.HelloWorldInC#.cs: -------------------------------------------------------------------------------- 1 | // See https://aka.ms/new-console-template for more information 2 | #region INCLUDE 3 | Console.WriteLine("Hello. My name is Inigo Montoya."); 4 | #endregion INCLUDE 5 | -------------------------------------------------------------------------------- /src/Chapter01/Listing01.02.SampleNETCoreConsoleProjectFile.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/Chapter01/Listing01.03.MultipleStatementsOneOneLine.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_03; 2 | 3 | public class HelloWorld 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | Console.WriteLine("Up"); Console.WriteLine("Down"); 9 | #endregion INCLUDE 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Chapter01/Listing01.04.MultipleStatementsOnSeparateLines.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_04; 2 | 3 | public class HelloWorld 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | Console.WriteLine("Down"); 9 | Console.WriteLine("Side"); 10 | Console.WriteLine("Up"); 11 | #endregion INCLUDE 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Chapter01/Listing01.05.SplittingAStatementAcrossMultipleLines.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_05; 2 | 3 | public class HelloWorld 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | Console.WriteLine( 9 | "Hello. My name is Inigo Montoya."); 10 | #endregion INCLUDE 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Chapter01/Listing01.06.HelloWorldInC#.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_06; 2 | 3 | #region INCLUDE 4 | public class Program 5 | { 6 | public static void Main() 7 | { 8 | System.Console.WriteLine("Hello. My name is Inigo Montoya."); 9 | } 10 | } 11 | #endregion INCLUDE 12 | -------------------------------------------------------------------------------- /src/Chapter01/Listing01.07.BasicClassDeclaration.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_07; 2 | 3 | #region INCLUDE 4 | public class HelloWorld 5 | { 6 | // ... 7 | } 8 | #endregion INCLUDE 9 | -------------------------------------------------------------------------------- /src/Chapter01/Listing01.09.TheMainMethodWithParametersAndAReturn.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_09; 2 | 3 | public class Program 4 | { 5 | #region INCLUDE 6 | public static int Main(string[] args) 7 | { 8 | #region EXCLUDE 9 | return 0; 10 | #endregion EXCLUDE 11 | } 12 | #endregion INCLUDE 13 | } 14 | -------------------------------------------------------------------------------- /src/Chapter01/Listing01.10.NoIndentationFormatting.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_10; 2 | 3 | #region INCLUDE 4 | public class HelloWorld 5 | { 6 | public static void Main() 7 | { 8 | Console.WriteLine("Hello Inigo Montoya"); 9 | } 10 | } 11 | #endregion INCLUDE 12 | -------------------------------------------------------------------------------- /src/Chapter01/Listing01.11.RemovingWhitespace.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_11; 2 | 3 | #region INCLUDE 4 | public class HelloWorld{public static void Main() 5 | {Console.WriteLine("Hello Inigo Montoya");}} 6 | #endregion INCLUDE 7 | -------------------------------------------------------------------------------- /src/Chapter01/Listing01.12.DeclaringAndAssigningAVariable.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_12; 2 | 3 | #region INCLUDE 4 | public class MiracleMax 5 | { 6 | public static void Main() 7 | { 8 | string max; // "string" identifies the data type 9 | // "max" is the variable 10 | max = "Have fun storming the castle!"; 11 | Console.WriteLine(max); 12 | } 13 | } 14 | #endregion INCLUDE 15 | -------------------------------------------------------------------------------- /src/Chapter01/Listing01.13.DeclaringTwoVariablesWithinOneStatement.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_13; 2 | 3 | public class HelloWorld 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | string message1, message2; 9 | #endregion INCLUDE 10 | 11 | message1 = "My name is Inigo Montoya.";; 12 | message2 = "You killed my father...."; 13 | 14 | Console.WriteLine(message1); 15 | Console.WriteLine(message2); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter01/Listing01.15.AssignmentReturningAValueThatCanBeassignedAgain.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_15; 2 | 3 | #region INCLUDE 4 | public class StormingTheCastle 5 | { 6 | public static void Main() 7 | { 8 | // ... 9 | string requirements, miracleMax; 10 | requirements = miracleMax = "It would take a miracle."; 11 | #region EXCLUDE 12 | Console.WriteLine(miracleMax); 13 | #endregion EXCLUDE 14 | } 15 | } 16 | #endregion INCLUDE 17 | -------------------------------------------------------------------------------- /src/Chapter01/Listing01.17.UsingSystemConsoleRead.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_17; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | int readValue; 9 | char character; 10 | readValue = Console.Read(); 11 | character = (char) readValue; 12 | Console.Write(character); 13 | #endregion INCLUDE 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter02.Tests/Chapter02.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 02 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.01.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_01.Tests; 3 | 4 | [TestClass] 5 | public class LiteralValueTests 6 | { 7 | [TestMethod] 8 | public void Main_WriteNumbers() 9 | { 10 | string expected = 11 | $@"{42} 12 | {1.618034}"; 13 | 14 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 15 | expected, Program.Main); 16 | } 17 | } -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.02.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_02.Tests; 3 | 4 | [TestClass] 5 | public class LiteralValueTests 6 | { 7 | [TestMethod] 8 | public void Main_WriteNumbers() 9 | { 10 | string expected = $@"{1.618033988749895}"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.03.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_03.Tests; 3 | 4 | [TestClass] 5 | public class LiteralValueTests 6 | { 7 | [TestMethod] 8 | public void Main_WriteNumbers() 9 | { 10 | string expected = $@"{1.6180339887498948M}"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.04.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_04.Tests; 3 | 4 | [TestClass] 5 | public class LiteralValueTests 6 | { 7 | [TestMethod] 8 | public void Main_WriteNumbers() 9 | { 10 | const string expected = @"9814072356"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.05.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_05.Tests; 3 | 4 | [TestClass] 5 | public class LiteralValueTests 6 | { 7 | [TestMethod] 8 | public void Main_WriteNumbers() 9 | { 10 | string expected = $@"{6.023E+23}"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.06.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_06.Tests; 3 | 4 | [TestClass] 5 | public class LiteralValueTests 6 | { 7 | [TestMethod] 8 | public void Main_WriteHexadecimal() 9 | { 10 | const string expected = "42"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.07.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_07.Tests; 3 | 4 | [TestClass] 5 | public class LiteralValueTests 6 | { 7 | [TestMethod] 8 | public void Main_WriteBinary() 9 | { 10 | const string expected = "42"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.08.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_08.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_WriteDecimalAsHexadecimalUsingFormatSpecifier() 9 | { 10 | const string expected = "0x2A"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.10.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_10.Tests; 3 | 4 | [TestClass] 5 | public class Comparison 6 | { 7 | [TestMethod] 8 | public void Main_WriteBooleanStatements() 9 | { 10 | const string expected = "Help Requested: True"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.11.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_11.Tests; 3 | 4 | [TestClass] 5 | public class SingleQuoteTests 6 | { 7 | [TestMethod] 8 | public void Main_WriteSingleQuote() 9 | { 10 | const string expected = 11 | @"'"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, SingleQuote.Main); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.12.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_12.Tests; 3 | 4 | [TestClass] 5 | public class SingleQuoteTests 6 | { 7 | [TestMethod] 8 | public void Main_WriteSmiley() 9 | { 10 | const string expected = 11 | @":)"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, SingleQuote.Main); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.13.Tests.cs: -------------------------------------------------------------------------------- 1 | using IntelliTect.TestTools.Console; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_13.Tests; 4 | 5 | [TestClass] 6 | public class DuelOfWitsTests 7 | { 8 | [TestMethod] 9 | public void Main_WriteDizzyQuote() 10 | { 11 | const string expected = "\"Truly, you have a dizzying intellect.\"\n\"Wait 'til I get going!\"\n"; 12 | 13 | ConsoleAssert.Expect(expected, (Action)DuelOfWits.Main, NormalizeOptions.None); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.18.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_18.Tests; 3 | 4 | [TestClass] 5 | public class SingleRawLiteralTests 6 | { 7 | [TestMethod] 8 | public void Main_OutputsQuote() 9 | { 10 | const string expected = """Mama said, "Life was just a box of chocolates..." """; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.21.Tests.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_21.Tests; 4 | 5 | [TestClass] 6 | public class RawLiteralTests 7 | { 8 | [TestMethod] 9 | public void Main_OutputsJson() 10 | { 11 | string result = IntelliTect.TestTools.Console.ConsoleAssert.Execute("", Program.Main); 12 | Assert.IsNotNull(JsonDocument.Parse(result)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.22.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_22.Tests; 3 | 4 | [TestClass] 5 | public class PalindromeLengthTests 6 | { 7 | [TestMethod] 8 | public void Main_InputRacecar_OutputPalindromeSevenChars() 9 | { 10 | const string expected = 11 | @"Enter a palindrome: <>The palindrome ""racecar"" is 7 characters."; 13 | 14 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 15 | expected, PalindromeLength.Main); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.23.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_23.Tests; 3 | 4 | [TestClass] 5 | public class UppercaseTests 6 | { 7 | [TestMethod] 8 | public void Main_InputLorem_OutputNotCapitalized() 9 | { 10 | const string expected = 11 | @"Enter text: <>Lorem"; 13 | 14 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 15 | expected, Uppercase.Main); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.24.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_24.Tests; 3 | 4 | [TestClass] 5 | public class UppercaseTests 6 | { 7 | [TestMethod] 8 | public void Main_InputLorem_OutputIsCapitalized() 9 | { 10 | const string expected = 11 | @"Enter text: <>LOREM"; 13 | 14 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 15 | expected, Uppercase.Main); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.25.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_25.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_WriteOverflowExample() 9 | { 10 | const string expected = "The age is: "; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.26.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_26.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_NoException() 9 | { 10 | Program.Main(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.27.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_27.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_WriteOverflowExample() 9 | { 10 | const string expected = "-2147483648"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.28.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_28.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | [ExpectedException(typeof(System.OverflowException))] 9 | public void Main_IntegerOverFlow_ExceptionThrown() 10 | { 11 | IntelliTect.TestTools.Console.ConsoleAssert.Execute("", Program.Main); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.29.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_29.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_OverflowIntegerUnchecked_NoException() 9 | { 10 | IntelliTect.TestTools.Console.ConsoleAssert.Execute("", Program.Main); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.30.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_30.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_NotUsingTheCastOperatorForAnImplicitCast_NoException() 9 | { 10 | IntelliTect.TestTools.Console.ConsoleAssert.Execute("", Program.Main); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.31.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_31.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_UsingTheCastOperatorForAnImplicitCast_NoException() 9 | { 10 | IntelliTect.TestTools.Console.ConsoleAssert.Execute("", Program.Main); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.32.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_32.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_UsingIntParseToConvertAStringToANumericDataType_NoException() 9 | { 10 | IntelliTect.TestTools.Console.ConsoleAssert.Execute("", Program.Main); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.33.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_33.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_TypeConversionUsingSystemConvert_NoException() 9 | { 10 | IntelliTect.TestTools.Console.ConsoleAssert.Execute("", Program.Main); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Chapter02.Tests/Listing02.34.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_34.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_PrintBoolConvertedToString() 9 | { 10 | const string expected = "True"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter02/Listing02.01.SpecifyingLiteralValues.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_01; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | Console.WriteLine(42); 9 | 10 | Console.WriteLine(1.618034); 11 | #endregion INCLUDE 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /src/Chapter02/Listing02.02.SpecifyingALiteralDouble.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_02; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | Console.WriteLine(1.6180339887498948); 9 | #endregion INCLUDE 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /src/Chapter02/Listing02.03.SpecifyingALiteralDecimal.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_03; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | Console.WriteLine(1.6180339887498948M); 9 | #endregion INCLUDE 10 | } 11 | } -------------------------------------------------------------------------------- /src/Chapter02/Listing02.04.UsingTheDigitSeparator.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_04; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | Console.WriteLine(9_814_072_356M); 9 | #endregion INCLUDE 10 | } 11 | } -------------------------------------------------------------------------------- /src/Chapter02/Listing02.05.ExponentialNotation.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_05; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | Console.WriteLine(6.023E23F); 9 | #endregion INCLUDE 10 | } 11 | } -------------------------------------------------------------------------------- /src/Chapter02/Listing02.06.HexadecimalLiteralValue.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_06; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | //Display the value 42 using a hexadecimal literal 9 | Console.WriteLine(0x002A); 10 | #endregion INCLUDE 11 | } 12 | } -------------------------------------------------------------------------------- /src/Chapter02/Listing02.07.BinaryLiteralValue.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_07; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | // Display the value 42 using a binary literal 9 | Console.WriteLine(0b101010); 10 | #endregion INCLUDE 11 | } 12 | } -------------------------------------------------------------------------------- /src/Chapter02/Listing02.08.ExamplesOfAHexadecimalFormatSpecifier.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_08; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | //Displays "0x2A" 9 | Console.WriteLine($"0x{42:X}"); 10 | #endregion INCLUDE 11 | } 12 | } -------------------------------------------------------------------------------- /src/Chapter02/Listing02.11.DisplayingASingleQuoteUsingAnEscapeSequence.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_11; 2 | 3 | #region INCLUDE 4 | public class SingleQuote 5 | { 6 | public static void Main() 7 | { 8 | Console.WriteLine('\''); 9 | } 10 | } 11 | #endregion INCLUDE 12 | 13 | -------------------------------------------------------------------------------- /src/Chapter02/Listing02.12.UsingUnicodeEncodingToDisplayASmileyFace.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_12; 2 | 3 | public class SingleQuote 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | Console.Write('\u003A'); 9 | 10 | Console.WriteLine('\u0029'); 11 | #endregion INCLUDE 12 | } 13 | } -------------------------------------------------------------------------------- /src/Chapter02/Listing02.13.UsingTheNewlineCharacterToInsertANewline.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_13; 2 | 3 | public class DuelOfWits 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | Console.Write( 9 | "\"Truly, you have a dizzying intellect.\""); 10 | Console.Write("\n\"Wait 'til I get going!\"\n"); 11 | #endregion INCLUDE 12 | } 13 | } -------------------------------------------------------------------------------- /src/Chapter02/Listing02.14.DisplayingATriangleUsingAVerbatimStringLiteral.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_14; 2 | 3 | public class Triangle 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | Console.Write(@"Begin 9 | /\ 10 | / \ 11 | / \ 12 | / \ 13 | /________\ 14 | End"); 15 | #endregion INCLUDE 16 | } 17 | } -------------------------------------------------------------------------------- /src/Chapter02/Listing02.18.SingleLineRawStringLiteral.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_18; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | Console.WriteLine( 9 | """Mama said, "Life was just a box of chocolates..." """); 10 | #endregion INCLUDE 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Chapter02/Listing02.25.AssigningNullToAString.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_25; 2 | 3 | public class Program 4 | { 5 | #region INCLUDE 6 | public static void Main() 7 | { 8 | int? age; 9 | //... 10 | 11 | // Clear the value of age 12 | age = null; 13 | 14 | #region EXCLUDE 15 | Console.WriteLine($"The age is: {age}"); 16 | #endregion EXCLUDE 17 | } 18 | #endregion INCLUDE 19 | } 20 | -------------------------------------------------------------------------------- /src/Chapter02/Listing02.26.ExplicitCastExample.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_26; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | long longNumber = 50918309109; 9 | int intNumber = (int)longNumber; // (int) is a cast operator. 10 | #endregion INCLUDE 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Chapter02/Listing02.27.OverflowingAnIntegerValue.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_27; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | // int.MaxValue equals 2147483647 9 | int n = int.MaxValue; 10 | n = n + 1; 11 | Console.WriteLine(n); 12 | #endregion INCLUDE 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter02/Listing02.29.AnUncheckedBlockExample.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_29; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | unchecked 9 | { 10 | // int.MaxValue equals 2147483647 11 | int n = int.MaxValue; 12 | n = n + 1; 13 | Console.WriteLine(n); 14 | } 15 | #endregion INCLUDE 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /src/Chapter02/Listing02.30.NotUsingTheCastOperatorForAnImplicitCast.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_30; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | int intNumber = 31416; 9 | long longNumber = intNumber; 10 | #endregion INCLUDE 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/Chapter02/Listing02.31.UsingTheCastOperatorForAnImplicitCast.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_31; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | int intNumber = 31416; 9 | long longNumber = (long)intNumber; 10 | #endregion INCLUDE 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Chapter02/Listing02.32.UsingIntParseToConvertAStringToANumericDataType.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_32; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | string text = $"{9.11E-31}"; 9 | float kgElectronMass = float.Parse(text); 10 | #endregion INCLUDE 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/Chapter02/Listing02.33.TypeConversionUsingSystemConvert.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_33; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | string middleCText = $"{261.626}"; 9 | double middleC = Convert.ToDouble(middleCText); 10 | bool boolean = Convert.ToBoolean(middleC); 11 | #endregion INCLUDE 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /src/Chapter02/Listing02.34.UsingToStringToConvertToAString.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_34; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | bool boolean = true; 9 | string text = boolean.ToString(); 10 | // Display "True" 11 | Console.WriteLine(text); 12 | #endregion INCLUDE 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/Chapter03.Tests/Chapter03.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 03 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/Chapter03.Tests/Listing03.03.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_03.Tests; 3 | 4 | [TestClass] 5 | public class UppercaseTests 6 | { 7 | [TestMethod] 8 | public void Main_GivenValidString_MakeUppercase() 9 | { 10 | const string expected = 11 | @"Enter text: <>TEST"; 13 | 14 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 15 | expected, Uppercase.Main); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter03.Tests/Listing03.05.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_05.Tests; 3 | 4 | 5 | [TestClass] 6 | public class ProgramTests 7 | { 8 | [TestMethod] 9 | public void Main_WriteInventions() 10 | { 11 | const string expected = 12 | @"Bifocals (1784) 13 | Phonograph (1877)"; 14 | 15 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 16 | expected, Program.Main); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Chapter03.Tests/Listing03.19.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_19.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_WriteInventions() 9 | { 10 | const string expected = 11 | @"TypeScript 12 | Python"; 13 | 14 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 15 | expected, Program.Main); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter03.Tests/Listing03.23.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_23.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_GetCountOnArray_ReturnArrayLength() 9 | { 10 | const string expected = 11 | "There are 9 languages in the array."; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter03.Tests/Listing03.24.Tests.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_24.Tests; 2 | 3 | [TestClass] 4 | public class ProgramTests 5 | { 6 | [TestMethod] 7 | public void Main_ThrowsIndexOutOfRangeException() 8 | { 9 | Assert.ThrowsException(Program.Main); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Chapter03.Tests/Listing03.28.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_28.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_GetLengthOfDimensionOf3DArray_ReturnsLength() 9 | { 10 | const string expected = 11 | "2\n3"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.03.WorkingWithStrings.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_03; 2 | 3 | public class Uppercase 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | Console.Write("Enter text: "); 9 | var text = Console.ReadLine(); 10 | 11 | // Return a new string in uppercase 12 | var uppercase = text.ToUpper(); 13 | 14 | Console.WriteLine(uppercase); 15 | #endregion INCLUDE 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.04.TheCSharpEquivalentOfCompilerGeneratedCILCodeForAValueTupleReturn.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_04 2 | { 3 | #region INCLUDE 4 | [return: System.Runtime.CompilerServices.TupleElementNames( 5 | new { "First", "Second" })] 6 | public System.ValueTuple ParseNames( 7 | string fullName) 8 | { 9 | // ... 10 | } 11 | #endregion INCLUDE 12 | } 13 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.06.DeclaringAnArray.cs: -------------------------------------------------------------------------------- 1 | #pragma warning disable CS0168 // Variable is declared but never used 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_06; 3 | 4 | public class Program 5 | { 6 | public static void Main() 7 | { 8 | #region INCLUDE 9 | string[] languages; 10 | #endregion INCLUDE 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.07.DeclaringATwoDimensionalArray.cs: -------------------------------------------------------------------------------- 1 | #pragma warning disable CS0168 // Variable is declared but never used 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_07; 3 | 4 | public class Program 5 | { 6 | public static void Main() 7 | { 8 | #region INCLUDE 9 | // | | 10 | // ---+---+--- 11 | // | | 12 | // ---+---+--- 13 | // | | 14 | int[,] cells; 15 | #endregion INCLUDE 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.08.ArrayDeclarationWithAssignment.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_08; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | string[] languages = { "C#", "COBOL", "Java", 9 | "C++", "TypeScript", "Visual Basic", 10 | "Python", "Lisp", "JavaScript" }; 11 | #endregion INCLUDE 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.09.ArrayAssignmentFollowingDeclaration.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_09; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | string[] languages; 9 | languages = new string[]{ "C#", "COBOL", "Java", 10 | "C++", "TypeScript", "Visual Basic", 11 | "Python", "Lisp", "JavaScript" }; 12 | #endregion INCLUDE 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.10.ArrayAssignmentWithNewDuringDeclaration.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_10; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | string[] languages = new string[]{ 9 | "C#", "COBOL", "Java", 10 | "C++", "TypeScript", "Visual Basic", 11 | "Python", "Lisp", "JavaScript" }; 12 | #endregion INCLUDE 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.11.DeclarationAndAssignmentWithTheNewKeyword.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_11; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | string[] languages = new string[9]{ 9 | "C#", "COBOL", "Java", 10 | "C++", "TypeScript", "Visual Basic", 11 | "Python", "Lisp", "JavaScript" }; 12 | #endregion INCLUDE 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.12.AssigningWithoutLiteralValues.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_12; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | string[] languages = new string[9]; 9 | #endregion INCLUDE 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.13.DefiningTheArraySizeAtRuntime.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_13; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | string[] groceryList; 9 | Console.Write("How many items on the list? "); 10 | int size = int.Parse(Console.ReadLine()); 11 | groceryList = new string[size]; 12 | // ... 13 | #endregion INCLUDE 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.14.DeclaringATwoDimensionalArray.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_14; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | int[,] cells = new int[3,3]; 9 | #endregion INCLUDE 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.15.InitializingATwoDimensionalArrayOfIntegers.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_15; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | int[,] cells = { 9 | {1, 0, 2}, 10 | {1, 2, 0}, 11 | {1, 2, 1} 12 | }; 13 | #endregion INCLUDE 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.18.InitializingAJaggedArray.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_18; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | int[][] cells = { 9 | new [] {1, 0, 2, 0}, 10 | new [] {1, 2, 0}, 11 | new [] {1, 2}, 12 | new [] {1} 13 | }; 14 | #endregion INCLUDE 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.21.InitializingATwoDimensionalArrayOfIntegers.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_21; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | int[,] cells = { 9 | {1, 0, 2}, 10 | {0, 2, 0}, 11 | {1, 2, 1} 12 | }; 13 | // Set the winning tic-tac-toe move to be player 1 14 | cells[1, 0] = 1; 15 | #endregion INCLUDE 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.22.DeclaringAJaggedArray.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_22; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | int[][] cells = { 9 | new []{1, 0, 2}, 10 | new []{0, 2, 0}, 11 | new []{1, 2, 1} 12 | }; 13 | 14 | cells[1][0] = 1; 15 | // ... 16 | #endregion INCLUDE 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.23.RetrievingTheLengthOfAnArray.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_23; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | string[] languages = new string[9]; 8 | // ... 9 | #region INCLUDE 10 | Console.WriteLine( 11 | $"There are {languages.Length} languages in the array."); 12 | #endregion INCLUDE 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.24.AccessingOutsideTheBoundsOfAnArrayThrowingAnException.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_24; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | string[] languages = new string[9]; 9 | // ... 10 | // RUNTIME ERROR: index out of bounds - should 11 | // be 8 for the last element 12 | languages[4] = languages[9]; 13 | #endregion INCLUDE 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.28.RetrievingAParticularDimensionsSize.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_28; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | bool[, ,] cells; 9 | cells = new bool[2, 3, 3]; 10 | Console.WriteLine(cells.GetLength(0)); // Displays 2 11 | Console.WriteLine(cells.Rank); // Displays 3 12 | #endregion INCLUDE 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.29.LookingForCommandlineOptions.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_29; 2 | 3 | public class Program 4 | { 5 | #region INCLUDE 6 | public static void Main(string[] args) 7 | { 8 | // ... 9 | if(args[0][0] == '-') 10 | { 11 | // This parameter is an option 12 | } 13 | } 14 | #endregion INCLUDE 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter03/Listing03.30.LookingForCommandlineOptionsSimplified.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_30; 2 | 3 | public class Program 4 | { 5 | #region INCLUDE 6 | public static void Main(string[] args) 7 | { 8 | // ... 9 | string arg = args[0]; 10 | if(arg[0] == '-') 11 | { 12 | // This parameter is an option 13 | } 14 | } 15 | #endregion INCLUDE 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter03/Table03.03.a.CommonArrayCodingErrors.cs: -------------------------------------------------------------------------------- 1 | // Justification: Only snippets of source code shown for elucidation. 2 | #pragma warning disable CS0168 // Variable is declared but never used 3 | 4 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03; 5 | 6 | public partial class CommonArrayCodingErrors 7 | { 8 | // 1. 9 | public static void SquareBracketsOnVariableRatherThanType() 10 | { 11 | #if COMPILEERROR 12 | int numbers[]; 13 | #endif // COMPILEERROR 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter03/Table03.03.b.CommonArrayCodingErrors.cs: -------------------------------------------------------------------------------- 1 | // Justification: Only snippets of source code shown for elucidation. 2 | #pragma warning disable CS0168 // Variable is declared but never used 3 | 4 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03; 5 | 6 | public partial class CommonArrayCodingErrors 7 | { 8 | // 2. 9 | public static void NewKeywordWithDataTypeRequired() 10 | { 11 | #if COMPILEERROR 12 | int[] numbers; 13 | numbers = {42, 84, 168 }; 14 | #endif // COMPILEERROR 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter03/Table03.03.c.CommonArrayCodingErrors.cs: -------------------------------------------------------------------------------- 1 | // Justification: Only snippets of source code shown for elucidation. 2 | #pragma warning disable CS0168 // Variable is declared but never used 3 | 4 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03; 5 | 6 | public partial class CommonArrayCodingErrors 7 | { 8 | // 3. 9 | public static void ArraySizeCannotBeSpecifiedInDataType() 10 | { 11 | #if COMPILEERROR 12 | int[3] numbers = 13 | { 42, 84, 168 }; 14 | #endif // COMPILEERROR 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter03/Table03.03.d.CommonArrayCodingErrors.cs: -------------------------------------------------------------------------------- 1 | // Justification: Only snippets of source code shown for elucidation. 2 | #pragma warning disable CS0168 // Variable is declared but never used 3 | 4 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03; 5 | 6 | public partial class CommonArrayCodingErrors 7 | { 8 | // 4. 9 | public static void ArraySizeOrInitializerIsRequired() 10 | { 11 | #if COMPILEERROR 12 | int[] numbers = 13 | new int[]; 14 | #endif // COMPILEERROR 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter03/Table03.03.e.CommonArrayCodingErrors.cs: -------------------------------------------------------------------------------- 1 | // Justification: Only snippets of source code shown for elucidation. 2 | #pragma warning disable CS0168 // Variable is declared but never used 3 | 4 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03; 5 | 6 | public partial class CommonArrayCodingErrors 7 | { 8 | // 5. 9 | public static void ArraySizeWithEmptyInitializer() 10 | { 11 | #if COMPILEERROR 12 | int[] numbers = 13 | new int[3] { }; 14 | #endif // COMPILEERROR 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter03/Table03.03.f.CommonArrayCodingErrors.cs: -------------------------------------------------------------------------------- 1 | // Justification: Only snippets of source code shown for elucidation. 2 | #pragma warning disable CS0168 // Variable is declared but never used 3 | 4 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03; 5 | 6 | public partial class CommonArrayCodingErrors 7 | { 8 | // 6. 9 | public static void IndexingOffTheEndOfArray() 10 | { 11 | int[] numbers = 12 | new int[3]; 13 | Console.WriteLine( 14 | numbers[3]); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter03/Table03.03.g.CommonArrayCodingErrors.cs: -------------------------------------------------------------------------------- 1 | // Justification: Only snippets of source code shown for elucidation. 2 | #pragma warning disable CS0168 // Variable is declared but never used 3 | 4 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03; 5 | 6 | public partial class CommonArrayCodingErrors 7 | { 8 | // 7. 9 | public static void Hat0IsOnePastTheEndOfTheArray1() 10 | { 11 | int[] numbers = 12 | new int[3]; 13 | numbers[^0] = 42; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter03/Table03.03.h.CommonArrayCodingErrors.cs: -------------------------------------------------------------------------------- 1 | // Justification: Only snippets of source code shown for elucidation. 2 | #pragma warning disable CS0168 // Variable is declared but never used 3 | 4 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03; 5 | 6 | public partial class CommonArrayCodingErrors 7 | { 8 | // 8. 9 | public static void LastItemIsLengthMinus1() 10 | { 11 | int[] numbers = 12 | new int[3]; 13 | numbers[numbers.Length] 14 | = 42; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter04.Tests/Chapter04.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 04 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.01.SimpleOperator.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_01.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"2"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.02.Negative.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_02.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | string expected = $@"{-72748555131730M}"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.03.BinaryOperators.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_03.Tests; 3 | 4 | [TestClass] 5 | public class DivisionTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Enter the numerator: <<42 11 | >>Enter the denominator: <<5 12 | >>42 / 5 = 8 with remainder 2"; 13 | 14 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 15 | expected, Division.Main); 16 | } 17 | } -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.05.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_05.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_UseCharInArithmeticOperation_PrintCharacter() 9 | { 10 | const string expected = 11 | @"g"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.06.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_06.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_CharacterDistanceBetweenTwoCharacters_WriteIntegerDistance() 9 | { 10 | const string expected = 11 | @"3"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.08.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_08.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_DivideFloatBy0_WriteNaN() 9 | { 10 | const string expected = 11 | @"NaN"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.16.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_16.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_PostIncrementInteger_ResultNotIncremented() 9 | { 10 | const string expected = 11 | @"result = 123 and count = 124"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.17.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_17.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_PreIncrementInteger_ResultIsIncremented() 9 | { 10 | const string expected = 11 | @"result = 124 and count = 124"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.18.ComparingPrePostIncrementOperators.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_18.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = 11 | @"123, 124, 125 12 | 126, 127, 127"; 13 | 14 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 15 | expected, IncrementExample.Main); 16 | } 17 | } -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.20.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_20.Tests; 3 | 4 | [TestClass] 5 | public class FortyTwoTests 6 | { 7 | [TestMethod] 8 | public void Main_AdditionOperatorWithNonNumericType_StringConcatenated() 9 | { 10 | const string expected = 11 | @"The original Tacoma Bridge in Washington 12 | was brought down by a 42 mile/hour wind."; 13 | 14 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 15 | expected, FortyTwo.Main); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.22.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_22.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = 11 | @"<<9>>What is the maximum number of turns in tic-tac-toe? (Enter 0 to exit.): Correct, tic-tac-toe has a maximum of 9 turns."; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, TicTacToeTrivia.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.25.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_25.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | string expected = 11 | $@"Enter the radius of the circle: <<3 12 | >>The area of the circle is: {28.27}"; 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, CircleAreaCalculator.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.26.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_26.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | string expected = 11 | $@"The area of the circle is: {0.00M}"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.27.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_27.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | string expected = 11 | $@"The area of the circle is: {0.00M}"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.29.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_29.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_Input5_BooleanConditionHit() 9 | { 10 | const string expected = 11 | @"Tic-tac-toe has more than 5 maximum turns."; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.35.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_35.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_LogicalNotOnFalseBool_WriteTrue() 9 | { 10 | const string expected = 11 | @"result = True"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.40.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_40.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_Negative7RightShiftBitwiseBy2() 9 | { 10 | const string expected = 11 | @"x = -2."; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.41.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_41.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_BitwiseOperators_WriteAndOrXORValues() 9 | { 10 | const string expected = """ 11 | and = 4 12 | or = 15 13 | xor = 11 14 | """; 15 | 16 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 17 | expected, Program.Main); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.47.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_47.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = 11 | "0<5\t1<4\t2<3\t3>2\t4>1\t5>0\t"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.48.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_48.Tests; 3 | 4 | [TestClass] 5 | public class TicTacToeTests 6 | { 7 | [TestMethod] 8 | public void Main_DetermineRemainingMoves_WriteRemainingMoves() 9 | { 10 | const string expected = 11 | @"The available moves are as follows: 1 2 3 4 5 6 7 8 9 "; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, TicTacToe.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter04.Tests/Listing04.51.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_51.Tests; 3 | 4 | [TestClass] 5 | public class TicTacToeTests 6 | { 7 | [TestMethod] 8 | public void Main_BreakOnPlayerWinning_Player1Winner() 9 | { 10 | const string expected = 11 | @"Player 1 was the winner"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, TicTacToe.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.01.SimpleOperator.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_01; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | int difference = 4 - 2; 9 | #endregion INCLUDE 10 | Console.WriteLine(difference); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.02.Negative.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_02; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | // World Debt on 2022-11-06 9 | // see https://worlddebtclocks.com/ 10 | decimal debt = -72748555131730M; 11 | #endregion INCLUDE 12 | 13 | Console.WriteLine(debt); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.04.NonNumericTypes.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_04; 2 | 3 | #region INCLUDE 4 | public class FortyTwo 5 | { 6 | public static void Main() 7 | { 8 | short windSpeed = 42; 9 | Console.WriteLine( 10 | $"The original Tacoma Bridge in Washington" + 11 | $"{Environment.NewLine}was " 12 | + "brought down by a " 13 | + windSpeed + " mile/hour wind."); 14 | } 15 | } 16 | #endregion INCLUDE 17 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.05.CharConcatenation.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_05; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | int n = '3' + '4'; 9 | char c = (char)n; 10 | Console.WriteLine(c); // Writes out g 11 | #endregion INCLUDE 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.06.CharDifferences.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_06; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | int distance = 'f' - 'c'; 9 | Console.WriteLine(distance); 10 | #endregion INCLUDE 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.08.DivisionByZero.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_08; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | float n = 0f; 9 | // Displays: NaN 10 | Console.WriteLine(n / 0); 11 | #endregion INCLUDE 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.09.BoundOverflow.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_09; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | // Displays: -Infinity 9 | Console.WriteLine(-1f / 0); 10 | // Displays: Infinity 11 | Console.WriteLine(3.402823E+38f * 2f); 12 | #endregion INCLUDE 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.10.Increment.cs: -------------------------------------------------------------------------------- 1 | // Justification: Demonstrating the without += just prior showing += 2 | #pragma warning disable IDE0054 // Use compound assignment 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_10; 4 | 5 | public class Program 6 | { 7 | public static void Main() 8 | { 9 | #region INCLUDE 10 | int x = 123; 11 | x = x + 2; 12 | #endregion INCLUDE 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.11.IncrementOperator.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_11; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | int x = 123; 9 | x += 2; 10 | #endregion INCLUDE 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.12.OtherOperators.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_12; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | int x = 0; 8 | 9 | #region INCLUDE 10 | x -= 2; 11 | x /= 2; 12 | x *= 2; 13 | x %= 2; 14 | #endregion INCLUDE 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.13.UnaryIncrement.cs: -------------------------------------------------------------------------------- 1 | // Justification: Demonstrating the equivalent operators 2 | #pragma warning disable IDE0054 // Use compound assignment 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_13; 4 | 5 | public class Program 6 | { 7 | public static void Main() 8 | { 9 | int spaceCount = 0; 10 | 11 | #region INCLUDE 12 | spaceCount = spaceCount + 1; 13 | spaceCount += 1; 14 | spaceCount++; 15 | #endregion INCLUDE 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.14.UnaryDecrement.cs: -------------------------------------------------------------------------------- 1 | // Justification: Demonstrating equivalent operators. 2 | #pragma warning disable IDE0054 // Use compound assignment 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_14; 4 | 5 | public class Program 6 | { 7 | public static void Main() 8 | { 9 | int lines = 0; 10 | 11 | #region INCLUDE 12 | lines = lines - 1; 13 | lines -= 1; 14 | lines--; 15 | #endregion INCLUDE 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.16.PostIncrement.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_16; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | int count = 123; 9 | int result; 10 | result = count++; 11 | Console.WriteLine( 12 | $"result = {result} and count = {count}"); 13 | #endregion INCLUDE 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.17.PreIncrement.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_17; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | int count = 123; 9 | int result; 10 | #region HIGHLIGHT 11 | result = ++count; 12 | #endregion HIGHLIGHT 13 | Console.WriteLine( 14 | $"result = {result} and count = {count}"); 15 | #endregion INCLUDE 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.24.NoCodeBlock.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_24; 2 | 3 | public class Program 4 | { 5 | public static void Main(params string[] args) 6 | { 7 | int input = int.Parse(args[0]); 8 | 9 | #region INCLUDE 10 | if (input < 0) 11 | #region HIGHLIGHT 12 | Console.WriteLine("Exiting"); 13 | #endregion HIGHLIGHT 14 | #endregion INCLUDE 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.26.RelyingOnIndentation.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_26; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | double radius = -1; 8 | double area = 0; 9 | 10 | #region INCLUDE 11 | if (radius >= 0) 12 | area = Math.PI * radius * radius; 13 | Console.WriteLine( 14 | $"The area of the circle is: {area:0.00}"); 15 | #endregion INCLUDE 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.27.IfStatementWithCurlyBraces.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_27; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | double radius = -1; 8 | double area = 0; 9 | 10 | #region INCLUDE 11 | if (radius >= 0) 12 | { 13 | area = Math.PI * radius * radius; 14 | } 15 | Console.WriteLine( 16 | $"The area of the circle is: {area:0.00}"); 17 | #endregion INCLUDE 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.30.AssignmentAsCondition.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_30; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | /* 8 | #region INCLUDE 9 | if (input = 9) // Allowed in C++, not in C# 10 | System.Console.WriteLine( 11 | "Correct, tic-tac-toe has a maximum of 9 turns."); 12 | #endregion INCLUDE 13 | */ 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.31.AssignAsBool.cs: -------------------------------------------------------------------------------- 1 | #pragma warning disable CS0219 // Variable is assigned but its value is never used 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_31; 4 | 5 | public class Program 6 | { 7 | public static void Main() 8 | { 9 | #region INCLUDE 10 | bool result = 70 > 7; 11 | #endregion INCLUDE 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.32.EqualityOperator.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_32; 2 | 3 | public class Program 4 | { 5 | public static void Main(params string[] args) 6 | { 7 | string input = args[0]; 8 | string currentPlayer = args[1]; 9 | #region INCLUDE 10 | if (input.Length == 0 || input == "quit") 11 | { 12 | Console.WriteLine($"Player {currentPlayer} quit!!"); 13 | } 14 | #endregion INCLUDE 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.33.OrOperator.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_33; 2 | 3 | public class Program 4 | { 5 | public static void Main(params string[] args) 6 | { 7 | int hourOfTheDay = int.Parse(args[0]); 8 | 9 | #region INCLUDE 10 | if ((hourOfTheDay > 23) || (hourOfTheDay < 0)) 11 | Console.WriteLine("The time you entered is invalid."); 12 | #endregion INCLUDE 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.34.AndOperator.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_34; 2 | 3 | public class Program 4 | { 5 | public static void Main(params string[] args) 6 | { 7 | int hourOfTheDay = int.Parse(args[0]); 8 | 9 | #region INCLUDE 10 | if ((10 < hourOfTheDay) && (hourOfTheDay < 24)) 11 | Console.WriteLine( 12 | "Hi-Ho, Hi-Ho, it's off to work we go."); 13 | #endregion INCLUDE 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.35.LogicalNegationOperator.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_35; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | bool valid = false; 9 | #region HIGHLIGHT 10 | bool result = !valid; 11 | #endregion HIGHLIGHT 12 | // Displays "result = True" 13 | Console.WriteLine($"result = { result }"); 14 | #endregion INCLUDE 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.40.RightShiftOperator.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_40; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | int x; 9 | x = (-7 >> 2); // 11111111111111111111111111111001 becomes 10 | // 11111111111111111111111111111110 11 | // Write out "x is -2." 12 | Console.WriteLine($"x = {x}."); 13 | #endregion INCLUDE 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.47.ForWithMultipleExpressions.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_47; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | for (int x = 0, y = 5; ((x <= 5) && (y >= 0)); y--, x++) 9 | { 10 | Console.Write( 11 | $"{ x }{ ((x > y) ? '>' : '<')}{ y }\t"); 12 | } 13 | #endregion INCLUDE 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.56.ExcludingCode.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_56; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | // ... 8 | #region INCLUDE 9 | #if CSHARP2PLUS 10 | System.Console.Clear(); 11 | #endif 12 | #endregion INCLUDE 13 | // ... 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.57.Directives.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_57; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | #if LINUX 9 | // ... 10 | #elif WINDOWS 11 | // ... 12 | #endif 13 | #endregion INCLUDE 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.58.DefineDirective.cs: -------------------------------------------------------------------------------- 1 | #region INCLUDE 2 | #define CSHARP2PLUS 3 | #endregion INCLUDE 4 | 5 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_58; 6 | 7 | public class Program 8 | { 9 | public static void Main() 10 | { 11 | // ... 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.59.WarningDirective.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_59; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | #warning "Same move allowed multiple times." 9 | #endregion INCLUDE 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.60.PragmaDirective.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_60; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | #pragma warning disable CS1030 9 | #endregion INCLUDE 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Chapter04/Listing04.61.PragmaRestore.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_61; 2 | 3 | public class Program 4 | { 5 | #pragma warning disable CS1030 6 | public static void Main() 7 | { 8 | #warning "Sample warning suppressed by #pragma warning disable." 9 | } 10 | #region INCLUDE 11 | #pragma warning restore CS1030 12 | #endregion INCLUDE 13 | } 14 | -------------------------------------------------------------------------------- /src/Chapter05.Tests/Constants.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Tests; 2 | 3 | public class Constants 4 | { 5 | public const string Inigo = "Inigo"; 6 | public const string Montoya = "Montoya"; 7 | } 8 | -------------------------------------------------------------------------------- /src/Chapter05.Tests/GlobalUsings.cs: -------------------------------------------------------------------------------- 1 | global using static AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Tests.Constants; -------------------------------------------------------------------------------- /src/Chapter05.Tests/Listing05.03.PassingAMethodReturnAsAParameterToAnotherMethodCall.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_03.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_InputInigo_WriteHelloInigo() 9 | { 10 | const string expected = 11 | @"Enter your first name: <>Hello Inigo!"; 13 | 14 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 15 | expected, Program.Main); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter05.Tests/Listing05.16.PassingVariablesByValue.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_16.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_WritePath() 9 | { 10 | string view = $"C:{Path.DirectorySeparatorChar}{Path.Combine("Data", "index.html")}"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect(view, 13 | () => 14 | { 15 | Program.Main(); 16 | }); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Chapter05.Tests/Listing05.17.PassingVariablesByReference.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_17.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_WriteSwappedVariables() 9 | { 10 | string view = @"first = ""goodbye"", second = ""hello"""; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect(view, 13 | () => 14 | { 15 | Program.Main(); 16 | }); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Chapter05.Tests/Listing05.19.ReturningAReference.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_19.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_InputInigoMontoya_WriteFullName() 9 | { 10 | string expected = @"image\[*\]=Red 11 | image\[*\]=Yellow"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.ExpectLike(expected, 14 | () => Program.Main()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter05/Listing05.03.PassingAMethodReturnAsAParameterToAnotherMehtodCall.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_03; 2 | 3 | public class Program 4 | { 5 | #region INCLUDE 6 | public static void Main() 7 | { 8 | Console.Write("Enter your first name: "); 9 | #region HIGHLIGHT 10 | Console.WriteLine($"Hello { Console.ReadLine() }!"); 11 | #endregion HIGHLIGHT 12 | } 13 | #endregion INCLUDE 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter05/Listing05.09.ImplicitUsingsGeneratedGlocalUsingDeclaratives.cs: -------------------------------------------------------------------------------- 1 | #region INCLUDE 2 | // 3 | global using global::System; 4 | global using global::System.Collections.Generic; 5 | global using global::System.IO; 6 | global using global::System.Linq; 7 | global using global::System.Net.Http; 8 | global using global::System.Threading; 9 | global using global::System.Threading.Tasks; 10 | #endregion INCLUDE 11 | -------------------------------------------------------------------------------- /src/Chapter05/Listing05.11.SampleConsoleProjectFileWithUsingElement.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net7.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/Chapter06.Tests/Chapter06.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 06 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.01.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_01.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"No output in this example"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.08.AccessingFieldsFromOutsideTheContainingClass.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_08.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_AccessingFieldsFromOutsideClass_WriteFieldValues() 9 | { 10 | const string expected = 11 | @"Inigo Montoya: Enough to survive on"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.11.UsingThisWithAMethod.Tests.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_11.Tests; 2 | 3 | [TestClass] 4 | public class ProgramTests 5 | { 6 | [TestMethod] 7 | public void Main_AccessMethodWithThis_WriteMethodResult() 8 | { 9 | const string expected = 10 | @"Name changed to 'Inigo Montoya'"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.14.DataRetrievalFromAFile.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_14.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_WriteToFileThenRetrieveDataFromFile_WriteStoredDataToScreen() 9 | { 10 | const string expected = 11 | @"Name changed to 'Inigo Montoya' 12 | Inigo Montoya: "; 13 | 14 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 15 | expected, Program.Main); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.15.Tests.cs: -------------------------------------------------------------------------------- 1 | using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_15.Tests; 4 | 5 | [TestClass] 6 | public class ProgramTests 7 | { 8 | [TestMethod] 9 | public async Task UnassignedVariableThrowsError() 10 | { 11 | await CompilerAssert.CompileTestTargetFileAsync( 12 | new string[] { "CS0122"}); 13 | } 14 | } -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.17.DefiningProperties.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_17.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_PropertySetterGetter_WriteProperty() 9 | { 10 | const string expected = 11 | @"Inigo"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.18.DefiningPropertiesWithExpressionBodiedMembers.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_18.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_PropertySetterGetter_WriteProperty() 9 | { 10 | const string expected = 11 | @"Inigo"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.19.AutomaticallyImplementedProperties.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_19.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_AutoPropertySetterGetter_WriteGetterValue() 9 | { 10 | const string expected = 11 | @"Inigo 12 | Computer Nerd"; 13 | 14 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 15 | expected, Program.Main); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.21.Tests.cs: -------------------------------------------------------------------------------- 1 | using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_21.Tests; 4 | 5 | [TestClass] 6 | public class ProgramTests 7 | { 8 | [TestMethod] 9 | public async Task UnassignedVariableThrowsError() 10 | { 11 | await CompilerAssert.CompileTestTargetFileAsync(["CS0200"]); 12 | } 13 | } -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.22.DefiningProperties.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_22.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_CalculatedPropertySetGet_WriteGetterValue() 9 | { 10 | const string expected = 11 | @"Inigo Montoya"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.23.Tests.cs: -------------------------------------------------------------------------------- 1 | using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_23.Tests; 4 | 5 | [TestClass] 6 | public class ProgramTests 7 | { 8 | [TestMethod] 9 | public async Task UnassignedVariableThrowsError() 10 | { 11 | await CompilerAssert.CompileTestTargetFileAsync(["CS0272"]); 12 | } 13 | } -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.27.CallingAConstructor.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_27.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_UsingAConstructor_WriteFirstNameLastNameSalary() 9 | { 10 | const string expected = 11 | @"Inigo Montoya: Too Little"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.32.Tests.cs: -------------------------------------------------------------------------------- 1 | using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_32.Tests; 4 | 5 | [TestClass] 6 | public class ProgramTests 7 | { 8 | [TestMethod] 9 | public async Task Main_CompileErrorCS8852() 10 | { 11 | await CompilerAssert.CompileTestTargetFileAsync(["CS8852"]); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.33.OverloadingAConstructor.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_33.Tests; 3 | 4 | [TestClass] 5 | public class EmployeeTests 6 | { 7 | [TestMethod] 8 | public void EmployeeConstructor_TwoParameterConstructorSuccess() 9 | { 10 | Employee employee = new("Inigo", "Montoya"); 11 | 12 | Assert.AreEqual("Inigo", employee.FirstName); 13 | Assert.AreEqual("Montoya", employee.LastName); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.36.ProvidingValidationOnNon-NullableProperty.Tests.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_36.Tests; 2 | 3 | [TestClass] 4 | public class EmployeeTests 5 | { 6 | [TestMethod] 7 | public void MainTest() 8 | { 9 | const string expected = @"Inigo Montoya"; 10 | 11 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 12 | expected, Program.Main); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.46.Tests.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_46.Tests; 2 | 3 | [TestClass] 4 | public class EmployeeTests 5 | { 6 | [TestMethod] 7 | public void Employee_NextId_SetsAtDeclaration() 8 | { 9 | Assert.AreEqual(42, Employee.NextId); 10 | _ = new Employee(); 11 | Assert.AreEqual(42, Employee.NextId); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.47.AccessingAStaticField.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_47.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_AccessStaticField_EmployeeIdIncrements() 9 | { 10 | const string expected = 11 | @"Inigo Montoya (1000000) 12 | Princess Buttercup (1000001) 13 | NextId = 1000002"; 14 | 15 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 16 | expected, Program.Main); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.49.Tests.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_49.Tests; 2 | 3 | [TestClass] 4 | public class EmployeeTests 5 | { 6 | [TestMethod] 7 | public void Employee_NextId_GetsSetInStaticConstructor() 8 | { 9 | Assert.IsTrue((100 < Employee.NextId) && (Employee.NextId < 1000)); 10 | int id = Employee.NextId; 11 | _ = new Employee(); 12 | Assert.AreEqual(id, Employee.NextId); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.54.Tests.cs: -------------------------------------------------------------------------------- 1 | using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_54.Tests; 4 | 5 | [TestClass] 6 | public class EmployeeTests 7 | { 8 | [TestMethod] 9 | public async Task Employee_ReadonlyField_CompileErrorCS0191() 10 | { 11 | await CompilerAssert.CompileTestTargetFileAsync(["CS0191"]); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Chapter06.Tests/Listing06.55.DeclaringAReadOnlyAutomaticallyImplementedProperty.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_55.Tests; 3 | 4 | [TestClass] 5 | public class DirectoryTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"System.Boolean[,,]"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter06/Listing06.01.DefiningAClass.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_01; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | System.Console.WriteLine("No output in this example"); 8 | } 9 | } 10 | 11 | #region INCLUDE 12 | public class Employee 13 | { 14 | } 15 | #endregion INCLUDE 16 | -------------------------------------------------------------------------------- /src/Chapter06/Listing06.04.DeclaringFields.cs: -------------------------------------------------------------------------------- 1 | // Non-nullable field is uninitialized. Consider declaring as nullable. 2 | #pragma warning disable CS8618 3 | 4 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_04; 5 | 6 | #region INCLUDE 7 | public class Employee 8 | { 9 | public string FirstName; 10 | public string LastName; 11 | public string? Salary; 12 | } 13 | #endregion INCLUDE 14 | -------------------------------------------------------------------------------- /src/Chapter06/Listing06.05.SettingInitialValuesOfFieldsAtDeclarationTime.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_05; 2 | 3 | #region INCLUDE 4 | // Non-nullable field uninitialized warning disabled while code is incomplete 5 | #pragma warning disable CS8618 6 | public class Employee 7 | { 8 | public string FirstName; 9 | public string LastName; 10 | #region HIGHLIGHT 11 | public string? Salary = "Not enough"; 12 | #endregion HIGHLIGHT 13 | } 14 | #endregion INCLUDE 15 | -------------------------------------------------------------------------------- /src/Chapter06/Listing06.25.PropertiesAreAnExplicitConstructInCIL.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_25 2 | { 3 | #region INCLUDE 4 | .property instance string FirstName() 5 | { 6 | .get instance string Program::get_FirstName() 7 | .set instance void Program::set_FirstName(string) 8 | } // End of property Program::FirstName 9 | #endregion INCLUDE 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/Chapter06/Listing06.31.CallingAnObjectInitializer.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_31; 2 | 3 | using System.Collections.Generic; 4 | using Listing06_28; 5 | 6 | #region INCLUDE 7 | public class Program 8 | { 9 | public static void Main() 10 | { 11 | List employees = new() 12 | { 13 | new("Inigo", "Montoya"), 14 | new("Kevin", "Bost") 15 | }; 16 | // ... 17 | } 18 | } 19 | #endregion INCLUDE 20 | -------------------------------------------------------------------------------- /src/Chapter06/Listing06.46.AssigningAStaticFieldAtDeclaration.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_46; 2 | 3 | #region INCLUDE 4 | public class Employee 5 | { 6 | // ... 7 | #region HIGHLIGHT 8 | public static int NextId = 42; 9 | #endregion HIGHLIGHT 10 | // ... 11 | } 12 | #endregion INCLUDE 13 | -------------------------------------------------------------------------------- /src/Chapter06/Listing06.49.DeclaringAStaticConstructor.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_49; 2 | 3 | using System; 4 | 5 | #region INCLUDE 6 | public class Employee 7 | { 8 | static Employee() 9 | { 10 | Random randomGenerator = new(); 11 | NextId = randomGenerator.Next(101, 999); 12 | } 13 | 14 | // ... 15 | public static int NextId = 42; 16 | // ... 17 | } 18 | #endregion INCLUDE 19 | -------------------------------------------------------------------------------- /src/Chapter06/Listing06.53.DeclaringAConstantField.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_53; 2 | 3 | #region INCLUDE 4 | public class ConvertUnits 5 | { 6 | public const float CentimetersPerInch = 2.54F; 7 | public const int CupsPerGallon = 16; 8 | // ... 9 | } 10 | #endregion INCLUDE 11 | -------------------------------------------------------------------------------- /src/Chapter06/Listing06.57.DefiningAPartialClass.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_57; 2 | 3 | #region INCLUDE 4 | // File: Program1.cs 5 | partial class Program 6 | { 7 | } 8 | // File: Program2.cs 9 | partial class Program 10 | { 11 | } 12 | #endregion INCLUDE 13 | -------------------------------------------------------------------------------- /src/Chapter07.Tests/Chapter07.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 07 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Chapter07.Tests/Listing07.06.Tests.cs: -------------------------------------------------------------------------------- 1 | using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing07_06.Tests; 4 | 5 | [TestClass] 6 | public class ProgramTests 7 | { 8 | [TestMethod] 9 | public async Task PrivateMembersAreNotInheritedTests() 10 | { 11 | await CompilerAssert.CompileTestTargetFileAsync( 12 | new string[] { "CS0122" }); 13 | } 14 | } -------------------------------------------------------------------------------- /src/Chapter07.Tests/Listing07.07.Tests.cs: -------------------------------------------------------------------------------- 1 | using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing07_07.Tests; 4 | 5 | [TestClass] 6 | public class ProgramTests 7 | { 8 | [TestMethod] 9 | public async Task ProtectedMembersInaccessibleFromNonDerivedTypes() 10 | { 11 | await CompilerAssert.CompileTestTargetFileAsync( 12 | new string[] { "CS1540", "CS0122" }); 13 | } 14 | } -------------------------------------------------------------------------------- /src/Chapter07.Tests/Listing07.08.Tests.cs: -------------------------------------------------------------------------------- 1 | using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_08.Tests; 4 | 5 | [TestClass] 6 | public class ProgramTests 7 | { 8 | [TestMethod] 9 | public async Task UnassignedVariableThrowsError() 10 | { 11 | await CompilerAssert.CompileTestTargetFileAsync( 12 | new string[] { "CS0509" }); 13 | } 14 | } -------------------------------------------------------------------------------- /src/Chapter07.Tests/Listing07.09.OverridingAProperty.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_09.Tests; 3 | 4 | [TestClass] 5 | public class ContactTests 6 | { 7 | [TestMethod] 8 | public void NameProperty_Overridden() 9 | { 10 | Contact contact = new(); 11 | 12 | contact.Name = "Inigo Montoya"; 13 | 14 | Assert.AreEqual("Inigo", contact.FirstName); 15 | Assert.AreEqual("Montoya", contact.LastName); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter07.Tests/Listing07.10.RuntimeCallingTheMostDerivedImplementationOfAVirtualMethod.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_10.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_CallDerivedImplementation() 9 | { 10 | const string expected = 11 | @"Inigo Montoya"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter07.Tests/Listing07.11.CovariantReturnTypes.Tests.cs: -------------------------------------------------------------------------------- 1 | using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_11.Tests; 4 | 5 | [TestClass] 6 | public class ProgramTests 7 | { 8 | [TestMethod] 9 | public void CovariantReturnTypesTest() 10 | { 11 | Derived derived1 = new(); 12 | Derived create1 = derived1.Create(); 13 | 14 | Base derived2 = derived1; 15 | Base create2 = derived2.Create(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter07.Tests/Listing07.16.DefiningAnAbstractClass.Tests.cs: -------------------------------------------------------------------------------- 1 | using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_16.Tests; 4 | 5 | [TestClass] 6 | public class ProgramTests 7 | { 8 | [TestMethod] 9 | public async Task DefiningAnAbstractClassTest() 10 | { 11 | await CompilerAssert.CompileTestTargetFileAsync( 12 | new string[] { "CS0144" }); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter07.Tests/Listing07.32.RecursivePatternMatching.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_32.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | 8 | [TestMethod] 9 | public void RecursivePatternMatchingTest() 10 | { 11 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 12 | "(5, Princess)", () => Program.Main()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter07/Listing07.02.UsingInheritedMethods.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_02; 2 | 3 | using Listing07_01; 4 | 5 | #region INCLUDE 6 | public class Program 7 | { 8 | public static void Main() 9 | { 10 | Contact contact = new(); 11 | #region HIGHLIGHT 12 | contact.Name = "Inigo Montoya"; 13 | #endregion HIGHLIGHT 14 | 15 | // ... 16 | } 17 | } 18 | #endregion INCLUDE 19 | -------------------------------------------------------------------------------- /src/Chapter07/Listing07.03.ClassesDerivingFromEachOtherToFormAnInheritanceChain.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_03; 2 | 3 | #region INCLUDE 4 | public class PdaItem : object 5 | { 6 | // ... 7 | } 8 | public class Appointment : PdaItem 9 | { 10 | // ... 11 | } 12 | public class Contact : PdaItem 13 | { 14 | // ... 15 | } 16 | public class Customer : Contact 17 | { 18 | // ... 19 | } 20 | #endregion INCLUDE 21 | -------------------------------------------------------------------------------- /src/Chapter07/Listing07.08.PreventingDerivationWithSealedClasses.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_08; 2 | 3 | #region INCLUDE 4 | public sealed class CommandLineParser 5 | { 6 | // ... 7 | } 8 | 9 | #if COMPILEERROR // EXCLUDE 10 | // ERROR: Sealed classes cannot be derived from 11 | public sealed class DerivedCommandLineParser 12 | : CommandLineParser 13 | { 14 | // ... 15 | } 16 | #endif // COMPILEERROR // EXCLUDE 17 | #endregion INCLUDE 18 | -------------------------------------------------------------------------------- /src/Chapter07/Listing07.11.CovariantReturnTypes.cs: -------------------------------------------------------------------------------- 1 | #pragma warning disable IDE0059 // Unnecessary assignment of a value 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_11; 3 | 4 | #region INCLUDE 5 | public class Base 6 | { 7 | public virtual Base Create() => new(); 8 | } 9 | 10 | public class Derived : Base 11 | { 12 | public override Derived Create() => new(); 13 | } 14 | #endregion INCLUDE 15 | -------------------------------------------------------------------------------- /src/Chapter07/Listing07.13.SealingMembers.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_13; 2 | 3 | #region INCLUDE 4 | class A 5 | { 6 | public virtual void Method() 7 | { 8 | } 9 | } 10 | 11 | class B : A 12 | { 13 | public sealed override void Method() 14 | { 15 | } 16 | } 17 | 18 | class C : B 19 | { 20 | // ERROR: Cannot override sealed members 21 | //public override void Method() 22 | //{ 23 | //} 24 | } 25 | #endregion INCLUDE 26 | -------------------------------------------------------------------------------- /src/Chapter07/Listing07.19.System.ObjectDerivationImpliedWhenNoDerivationIsSpecifiedExplicitly.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_19; 2 | 3 | /* 4 | #region INCLUDE 5 | public class PdaItem 6 | { 7 | // ... 8 | } 9 | public class PdaItem : object 10 | { 11 | // ... 12 | } 13 | #endregion INCLUDE 14 | */ 15 | -------------------------------------------------------------------------------- /src/Chapter08.Tests/Chapter08.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Chapter08.Tests 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Chapter08.Tests/Listing08.07.DeclarationWithoutContainingInterface.Tests.cs: -------------------------------------------------------------------------------- 1 | using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_07.Tests; 4 | 5 | [TestClass] 6 | public class ContactTests 7 | { 8 | [TestMethod] 9 | public async Task DeclaringAMethodOnARelatedInterface_CompileError() 10 | { 11 | await CompilerAssert.CompileTestTargetFileAsync( 12 | new string[] { "CS0161", "CS0540" }); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter08/Chapter08.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Chapter08 4 | 5 | 6 | 7 | 8 | Program.cs 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/Chapter08/Listing08.01.DefiningAnInterface.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_01; 2 | 3 | #region INCLUDE 4 | interface IFileCompression 5 | { 6 | void Compress(string targetFileName, string[] fileList); 7 | void Uncompress( 8 | string compressedFileName, string expandDirectoryName); 9 | } 10 | #endregion INCLUDE 11 | -------------------------------------------------------------------------------- /src/Chapter09.Tests/Chapter09.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Chapter09.Tests 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/Chapter09.Tests/Listing09.03.Tests.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_03.Tests; 2 | 3 | [TestClass] 4 | public class AngleProgramTests 5 | { 6 | [TestMethod] 7 | public void Create_Angle_Success() 8 | { 9 | string expected = 10 | "Angle { Degrees = 90, Minutes = 0, Seconds = 0, Name = }"; 11 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 12 | expected, Program.Main); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter09.Tests/Listing09.27.SubtleBoxingIdiosyncrasies.Tests.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_27.Tests; 2 | 3 | [TestClass] 4 | public class ProgramTests 5 | { 6 | [TestMethod] 7 | public void Main_BoxIdiosyncrasies() 8 | { 9 | const string expected = @"25, 25, 25, 26"; 10 | 11 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 12 | expected, Program.Main); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter09.Tests/Listing09.28.AvoidingUnboxingAndCopying.Tests.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_28.Tests; 2 | 3 | [TestClass] 4 | public class ProgramTests 5 | { 6 | [TestMethod] 7 | public void Main_AvoidingUnboxingAndCopying() 8 | { 9 | const string expected = @"2A"; 10 | 11 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 12 | expected, Program.Main); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter09.Tests/Listing09.34.ConvertingAStringToAnEnumUsingEnum.TryParse.Tests.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_34.Tests; 2 | 3 | [TestClass] 4 | public class ProgramTests 5 | { 6 | [TestMethod] 7 | public void Main_TryParseThreadLevelPriorityEnumToStringUsing() 8 | { 9 | const string expected = "Idle"; 10 | 11 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 12 | expected, Program.Main); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter09/Chapter09.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Chapter09 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Program.cs 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/Chapter09/Listing09.01.ExampleStruct.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_01; 2 | 3 | #region INCLUDE 4 | public struct Angle 5 | { 6 | // ... 7 | } 8 | #endregion INCLUDE 9 | -------------------------------------------------------------------------------- /src/Chapter09/Listing09.02.BasicStruct.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_02; 2 | 3 | #region INCLUDE 4 | // Use the record struct construct to declare a value type 5 | public readonly record struct Angle( 6 | int Degrees, int Minutes, int Seconds, string? Name = null); 7 | #endregion INCLUDE 8 | -------------------------------------------------------------------------------- /src/Chapter09/Listing09.05.DeclaringRecordClass.cs: -------------------------------------------------------------------------------- 1 | using AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_02; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_05; 4 | #region INCLUDE 5 | // Use the record class construct to declare a reference type 6 | public record class Coordinate( 7 | Angle Longitude, Angle Latitude) 8 | #endregion INCLUDE 9 | { 10 | public Type ExternalEqualityContract => EqualityContract; 11 | } 12 | -------------------------------------------------------------------------------- /src/Chapter09/Listing09.07.RecordClassInheritance.cs: -------------------------------------------------------------------------------- 1 | using AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_02; 2 | using AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_05; 3 | 4 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_07; 5 | 6 | #region INCLUDE 7 | public record class NamedCoordinate( 8 | Angle Longitude, Angle Latitude, string Name) 9 | : Coordinate(Longitude, Latitude); 10 | 11 | #endregion INCLUDE 12 | -------------------------------------------------------------------------------- /src/Chapter09/Listing09.08.UsingReadOnlyModifierOnStructs.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_08; 2 | 3 | #region INCLUDE 4 | readonly struct Angle { } 5 | #endregion INCLUDE 6 | -------------------------------------------------------------------------------- /src/Chapter09/Listing09.12.RecordConstructors.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_12; 2 | 3 | public record struct Angle( 4 | int Degrees, int Minutes, int Seconds, string? Name = null) 5 | { 6 | 7 | #region INCLUDE 8 | public Angle( 9 | string degrees, string minutes, string seconds) 10 | : this(int.Parse(degrees), 11 | int.Parse(minutes), 12 | int.Parse(seconds)) 13 | { } 14 | #endregion INCLUDE 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter09/Listing09.13.RecordStructInitialization.cs: -------------------------------------------------------------------------------- 1 | using AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_02; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_13; 4 | 5 | public class Program { 6 | public static void Main() 7 | { 8 | #region INCLUDE 9 | Angle[] angles = new[42]; 10 | #endregion INCLUDE 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Chapter09/Listing09.17.CustomEqualityImplementation.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_17; 2 | 3 | public readonly record struct Angle( 4 | int Degrees, int Minutes, int Seconds, string? Name = null) 5 | { 6 | // Changing Equals() to ignore Name 7 | #region INCLUDE 8 | public bool Equals(Angle other) => 9 | (Degrees, Minutes, Seconds).Equals( 10 | (other.Degrees, other.Minutes, other.Seconds)); 11 | #endregion INCLUDE 12 | } 13 | -------------------------------------------------------------------------------- /src/Chapter09/Listing09.30.DefiningAnEnum.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_30; 2 | 3 | #region INCLUDE 4 | enum ConnectionState 5 | { 6 | Disconnected, 7 | Connecting, 8 | Connected, 9 | Disconnecting 10 | } 11 | #endregion INCLUDE 12 | -------------------------------------------------------------------------------- /src/Chapter09/Listing09.31.DefiningAnEnumType.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_31; 2 | 3 | #region INCLUDE 4 | enum ConnectionState : short 5 | { 6 | Disconnected, 7 | Connecting = 10, 8 | Connected, 9 | Joined = Connected, 10 | Disconnecting 11 | } 12 | #endregion INCLUDE 13 | -------------------------------------------------------------------------------- /src/Chapter09/Listing09.33.WritingEnumValueIdentifierToTraceBuffer.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_33; 2 | 3 | using AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_30; 4 | using System; 5 | public class Program 6 | { 7 | public static void Main() 8 | { 9 | #region INCLUDE 10 | System.Diagnostics.Trace.WriteLine( 11 | $"The connection is currently {ConnectionState.Disconnecting}"); 12 | #endregion INCLUDE 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter09/Listing09.34.ConvertingAStringToAnEnumUsingEnum.TryParse.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_34; 2 | 3 | using System; 4 | 5 | public class Program 6 | { 7 | public static void Main() 8 | { 9 | #region INCLUDE 10 | System.Diagnostics.ThreadPriorityLevel priority; 11 | if(Enum.TryParse("Idle", out priority)) 12 | { 13 | Console.WriteLine(priority); 14 | } 15 | #endregion INCLUDE 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter09/Listing09.37.DefiningEnumValuesforFrequentCombinations.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_37; 2 | 3 | using System; 4 | #region INCLUDE 5 | [Flags] 6 | enum DistributedChannel 7 | { 8 | None = 0, 9 | Transacted = 1, 10 | Queued = 2, 11 | Encrypted = 4, 12 | Persisted = 16, 13 | #region HIGHLIGHT 14 | FaultTolerant = 15 | Transacted | Queued | Persisted 16 | #endregion HIGHLIGHT 17 | } 18 | #endregion INCLUDE 19 | -------------------------------------------------------------------------------- /src/Chapter10.Tests/Listing10.16.ResourceCleanupWithIDisposable.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_16.Tests; 3 | 4 | [TestClass] 5 | public class SearchTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @""; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Search); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter10/Employee.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter10; 2 | 3 | class Employee 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /src/Chapter10/Listing10.08.MakingTypesAvailableExternally.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_08; 2 | 3 | #region INCLUDE 4 | public struct Coordinate 5 | { 6 | // ... 7 | } 8 | 9 | public struct Latitude 10 | { 11 | // ... 12 | } 13 | 14 | public struct Longitude 15 | { 16 | // ... 17 | } 18 | 19 | public struct Arc 20 | { 21 | // ... 22 | } 23 | #endregion INCLUDE 24 | -------------------------------------------------------------------------------- /src/Chapter10/Listing10.10.DefiningANamespace.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_09 2 | { 3 | #region INCLUDE 4 | // Define the namespace AddisonWesley 5 | #region HIGHLIGHT 6 | namespace AddisonWesley.Michaelis.EssentialCSharp 7 | { 8 | #endregion HIGHLIGHT 9 | class Program 10 | { 11 | // ... 12 | } 13 | #region HIGHLIGHT 14 | } 15 | #endregion HIGHLIGHT 16 | // End of AddisonWesley namespace declaration 17 | #endregion INCLUDE 18 | } 19 | -------------------------------------------------------------------------------- /src/Chapter11.Tests/Chapter11.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Chapter11.Tests 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Chapter11.Tests/Listing11.06.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter11.Listing11_06.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"-2147483648"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter11.Tests/Listing11.08.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter11.Listing11_08.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"-2147483648"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter11/Chapter11.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Chapter11 4 | 5 | 6 | 7 | 8 | 9 | Program.cs 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/Chapter11/Listing11.06.OverflowingAnIntegerValue.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter11.Listing11_06; 2 | 3 | #region INCLUDE 4 | using System; 5 | public class Program 6 | { 7 | public static void Main() 8 | { 9 | // int.MaxValue equals 2147483647 10 | int n = int.MaxValue; 11 | n = n + 1; 12 | Console.WriteLine(n); 13 | } 14 | } 15 | #endregion INCLUDE 16 | -------------------------------------------------------------------------------- /src/Chapter12.Tests/Chapter12.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 12 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Chapter12.Tests/Listing12.15.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_15.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"1914: Shackleton leaves for South Pole on ship Endurance"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter12.Tests/Listing12.36.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_36.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | string expected = $@"490{Environment.NewLine}Fireswamp"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter12.Tests/Listing12.37.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_37.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | string expected = $@"490{Environment.NewLine}Fireswamp"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter12.Tests/Listing12.41.Tests.cs: -------------------------------------------------------------------------------- 1 | using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_41.Tests; 4 | 5 | [TestClass] 6 | public class Listing12 7 | { 8 | [TestMethod] 9 | public async Task CannotConvertTypes() 10 | { 11 | await CompilerAssert.CompileTestTargetFileAsync( 12 | new string[] { "CS0030" }); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Chapter12/INullable.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_24; 2 | 3 | public interface INullable 4 | { 5 | bool IsNull { get; } 6 | } 7 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.01.TheSystemCollectionsStackMethodSignatures.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_01; 2 | 3 | #region INCLUDE 4 | public class Stack 5 | { 6 | public virtual object Pop() 7 | { 8 | #region EXCLUDE 9 | return new object(); 10 | #endregion EXCLUDE 11 | } 12 | 13 | public virtual void Push(object obj) 14 | { 15 | // ... 16 | } 17 | // ... 18 | } 19 | #endregion INCLUDE 20 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.03.DefiningASpecializedStackClass.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_03; 2 | 3 | using Listing12_02; 4 | #region INCLUDE 5 | public class CellStack 6 | { 7 | public virtual Cell Pop() { return new Cell(); } // would return 8 | // that last cell added and remove it from the list 9 | public virtual void Push(Cell cell) { } 10 | // ... 11 | } 12 | #endregion INCLUDE 13 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.08.DeclaringAGenericInterface.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_08; 2 | 3 | #region INCLUDE 4 | interface IPair 5 | { 6 | T First { get; set; } 7 | T Second { get; set; } 8 | } 9 | #endregion INCLUDE 10 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.09.ImplementingAGenericInterface.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_09; 2 | 3 | using Listing12_08; 4 | #region INCLUDE 5 | public struct Pair : IPair 6 | { 7 | public T First { get; set; } 8 | public T Second { get; set; } 9 | } 10 | #endregion INCLUDE 11 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.11.DeclaringAGenericTypeConstructor.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_11; 2 | 3 | using Listing12_08; 4 | #region INCLUDE 5 | public struct Pair : IPair 6 | { 7 | #region HIGHLIGHT 8 | public Pair(T first, T second) 9 | { 10 | First = first; 11 | Second = second; 12 | } 13 | #endregion HIGHLIGHT 14 | 15 | public T First { get; set; } 16 | public T Second { get; set; } 17 | } 18 | #endregion INCLUDE 19 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.19.DeclaringABinaryTreeClassWithNoConstraints.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_19; 2 | 3 | using Listing12_13; 4 | #region INCLUDE 5 | public class BinaryTree 6 | { 7 | public BinaryTree(T item) 8 | { 9 | Item = item; 10 | } 11 | 12 | public T Item { get; set; } 13 | public Pair> SubItems { get; set; } 14 | } 15 | #endregion INCLUDE 16 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.23.DeclaringABaseClassConstraint.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_23; 2 | 3 | #region INCLUDE 4 | public class EntityDictionary 5 | : System.Collections.Generic.Dictionary 6 | #region HIGHLIGHT 7 | where TKey : notnull 8 | where TValue : EntityBase 9 | #endregion HIGHLIGHT 10 | { 11 | // ... 12 | } 13 | #endregion INCLUDE 14 | public class EntityBase 15 | { 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.26.SpecifyingMultipleConstraints.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_25; 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using Listing12_23; 6 | #region INCLUDE 7 | public class EntityDictionary 8 | : Dictionary 9 | where TKey : IComparable, IFormattable 10 | where TValue : EntityBase 11 | { 12 | // ... 13 | } 14 | #endregion INCLUDE 15 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.31.InheritedConstraintsSpecifiedExplicitly.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_31; 2 | 3 | using System; 4 | #region INCLUDE 5 | public class EntityBase where T : IComparable 6 | { 7 | // ... 8 | } 9 | 10 | // ERROR: 11 | // The type 'U' must be convertible to 'System.IComparable' 12 | // to use it as parameter 'T' in the generic type or 13 | // method 14 | // class Entity : EntityBase 15 | // { 16 | // ... 17 | // } 18 | #endregion INCLUDE 19 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.33.ConstraintExpressionsCannotRequireOperators.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_33; 2 | 3 | /* 4 | #region INCLUDE 5 | public abstract class MathEx 6 | { 7 | public static T Add(T first, T second) 8 | { 9 | // Error: Operator '+' cannot be applied to 10 | // operands of type 'T' and 'T' 11 | #region HIGHLIGHT 12 | // return first + second; 13 | #endregion HIGHLIGHT 14 | } 15 | } 16 | #endregion INCLUDE 17 | */ 18 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.34.CombiningConstraintsUsingOrRelationshipNotAllowed.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_30; 2 | 3 | #region INCLUDE 4 | public class BinaryTree 5 | // Error: OR is not supported 6 | // where T: System.IComparable || System.IFormattable 7 | { 8 | // ... 9 | } 10 | #endregion INCLUDE 11 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.36.SpecifyingTheTypeParameterExplicitly.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_36; 2 | 3 | using System; 4 | using Listing12_35; 5 | 6 | public class Program 7 | { 8 | public static void Main() 9 | { 10 | #region INCLUDE 11 | Console.WriteLine( 12 | MathEx.Max(7, 490)); 13 | Console.WriteLine( 14 | MathEx.Min("R.O.U.S.", "Fireswamp")); 15 | #endregion INCLUDE 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.37.InferringTheTypeParameter.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_37; 2 | 3 | using System; 4 | using Listing12_35; 5 | 6 | public class Program 7 | { 8 | public static void Main() 9 | { 10 | #region INCLUDE 11 | Console.WriteLine( 12 | MathEx.Max(7, 490)); // No type arguments! 13 | Console.WriteLine( 14 | MathEx.Min("R.O.U.S'", "Fireswamp")); 15 | #endregion INCLUDE 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.39.BinaryTreeRequiringIComparableTypeParameters.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_39; 2 | 3 | #region INCLUDE 4 | public class BinaryTree 5 | #region HIGHLIGHT 6 | where T : System.IComparable 7 | #endregion HIGHLIGHT 8 | { 9 | //... 10 | } 11 | #endregion INCLUDE 12 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.40.ConversionBetweenGenericsWithDifferentTypeParameters.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_40; 2 | 3 | public class Program 4 | { 5 | public static void Main() 6 | { 7 | /* 8 | #region INCLUDE 9 | // ... 10 | // Error: Cannot convert type ... 11 | Pair pair = (Pair)new Pair(); 12 | IPair duple = (IPair)new Pair(); 13 | #endregion INCLUDE 14 | */ 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.47.CILCodeForStack.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_47; 2 | 3 | // CIL CODE BELOW 4 | /* 5 | #region INCLUDE 6 | .class private auto ansi beforefieldinit 7 | Stack'1<([mscorlib]System.IComparable)T> 8 | extends [mscorlib]System.Object 9 | { 10 | ... 11 | } 12 | #endregion INCLUDE 13 | */ 14 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.48.CILWithExclamationPointNotation.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_48; 2 | 3 | // CIL CODE BELOW 4 | /* 5 | #region INCLUDE 6 | .class public auto ansi beforefieldinit 7 | 'Stack'1'<([mscorlib]System.IComparable) T> 8 | extends [mscorlib]System.Object 9 | { 10 | #region HIGHLIGHT 11 | .field private !0[ ] _Items 12 | #endregion HIGHLIGHT 13 | ... 14 | } 15 | #endregion INCLUDE 16 | */ 17 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.49.StackIntDefinition.cs: -------------------------------------------------------------------------------- 1 | // Justification: Only showing partial implementation. 2 | #pragma warning disable CS0168 // Variable is declared but never used 3 | 4 | 5 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_49; 6 | 7 | public class Program 8 | { 9 | private static void Main() 10 | { 11 | #region INCLUDE 12 | Stack stack; 13 | #endregion INCLUDE 14 | 15 | // ... 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter12/Listing12.50.DeclaringVariablesOfTypeStack.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_50; 2 | 3 | public class Program 4 | { 5 | #region INCLUDE 6 | Stack stackOne = new(); 7 | Stack stackTwo = new(); 8 | #endregion INCLUDE 9 | } 10 | -------------------------------------------------------------------------------- /src/Chapter13.Tests/Chapter13.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 13 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Chapter13.Tests/Listing13.08.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_08.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Enter an integer: '' is not a valid integer."; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, DelegateSample.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter13.Tests/Listing13.12.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_12.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Enter an integer: '' is not a valid integer."; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, DelegateSample.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter13.Tests/Listing13.13.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_13.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Enter an integer: '' is not a valid integer."; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter13.Tests/Listing13.15.Tests.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_15.Tests; 2 | 3 | [TestClass] 4 | public class ProgramTests 5 | { 6 | [TestMethod] 7 | public void MainTest() 8 | { 9 | const string expected = "<>ValidInput"; 10 | 11 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 12 | expected, Program.Main 13 | ); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter13.Tests/Listing13.16.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_16.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Enter an integer: '' is not a valid integer."; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter13.Tests/Listing13.17.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_17.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Enter an integer: '' is not a valid integer."; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter13.Tests/Listing13.18.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_18.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @""; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter13.Tests/Listing13.19.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_19.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Enter an integer: '' is not a valid integer."; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, DelegateSample.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter13.Tests/Listing13.22.CSharpEquivalentOfCILCodeGeneratedByCompilerForOuterVariables.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_22.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Enter an integer: '' is not a valid integer."; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter13.Tests/Listing13.23.CapturingLoopVariablesCSharpFive.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_23.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | string expected = $@"Moe{Environment.NewLine}Larry{Environment.NewLine}Curly"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, CaptureLoop.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter13.Tests/Listing13.24.LoopVariableWorkaroundBeforeCSharpFive.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_24.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | string expected = $@"Moe{Environment.NewLine}Larry{Environment.NewLine}Curly"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, DoNotCaptureLoop.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter13/Chapter13.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 13 4 | 5 | 6 | 7 | 8 | Program.cs 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/Chapter13/Listing13.05.DeclaringADelegateType.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_05; 2 | 3 | #region INCLUDE 4 | public delegate bool Comparer( 5 | int first, int second); 6 | #endregion INCLUDE 7 | -------------------------------------------------------------------------------- /src/Chapter13/Listing13.06.DeclaringANestedDelegateType.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_06; 2 | 3 | #region INCLUDE 4 | public class DelegateSample 5 | { 6 | public delegate bool ComparisonHandler( 7 | int first, int second); 8 | } 9 | #endregion INCLUDE 10 | -------------------------------------------------------------------------------- /src/Chapter13/Listing13.10.SystemDelegateCannotBeBaseClass.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_10; 2 | 3 | /* 4 | #region INCLUDE 5 | // ERROR: Func cannot 6 | // inherit from special class 'System.Delegate' 7 | public class Func: System.Delegate 8 | { 9 | // ... 10 | } 11 | #endregion INCLUDE 12 | */ -------------------------------------------------------------------------------- /src/Chapter13/Listing13.25.ConvertingExpressionTreeToSqlWhereClause.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_25; 2 | 3 | /* 4 | #region INCLUDE 5 | EXPRESSION TREE: 6 | persons.Where(person => person.Name.ToUpper() == "INIGO MONTOYA"); 7 | 8 | SQL WHERE CLAUSE: 9 | select * from Person where upper(Name) = 'INIGO MONTOYA'; 10 | #endregion INCLUDE 11 | */ 12 | -------------------------------------------------------------------------------- /src/Chapter13/Program_Main.sequencediagram: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /src/Chapter13/Program_Main.sequencediagram.layout: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /src/Chapter13/Program_Main_1.sequencediagram: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /src/Chapter13/Program_Main_1.sequencediagram.layout: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /src/Chapter13/Program_Main_2.sequencediagram: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /src/Chapter13/Program_Main_2.sequencediagram.layout: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /src/Chapter14.Tests/Chapter14.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 14 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/Chapter14.Tests/Listing14.03.ConnectingThePublisherAndSubscribers.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_03.Tests; 3 | 4 | 5 | [TestClass] 6 | public class ProgramTests 7 | { 8 | [TestMethod] 9 | public void ConnectingPublisherAndSubscribers() 10 | { 11 | string expected = @"Enter temperature: <<1"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, 14 | () => 15 | { 16 | Program.Main(); 17 | }); 18 | } 19 | } -------------------------------------------------------------------------------- /src/Chapter14.Tests/Listing14.08.OnTemperatureChangedThrowingAnException.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_08.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Enter temperature: '' is not a valid integer."; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter14.Tests/Listing14.09.HandlingExceptionsFromSubscribers.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_09.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Enter temperature: '' is not a valid integer."; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter14.Tests/Listing14.10.UsingTheAssignmentOperationRatherThanPlusEquals.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_10.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Enter temperature: '' is not a valid integer."; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter14/Chapter14.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 14 4 | 5 | 6 | 7 | 8 | Program.cs 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/Chapter14/Listing14.02.DefiningTheEventPublsherThermostat.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_02; 2 | 3 | using System; 4 | #region INCLUDE 5 | public class Thermostat 6 | { 7 | // Define the event publisher (initially without the sender) 8 | public Action? OnTemperatureChange { get; set; } 9 | 10 | public float CurrentTemperature { get; set; } 11 | #endregion INCLUDE 12 | } -------------------------------------------------------------------------------- /src/Chapter14/Listing14.13.DeclaringAGenericDelegateType.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_13; 2 | 3 | using System; 4 | 5 | public class Thermostat 6 | { 7 | #region INCLUDE 8 | public delegate void EventHandler( 9 | object sender, TEventArgs e) 10 | where TEventArgs : EventArgs; 11 | #endregion INCLUDE 12 | } 13 | -------------------------------------------------------------------------------- /src/Chapter15.Tests/Chapter15.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 15 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Chapter15.Tests/Listing15.03.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_03.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"1 11 | 2 12 | 3 13 | 4 14 | 5 15 | 6"; 16 | 17 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 18 | expected, Program.Main); 19 | } 20 | } -------------------------------------------------------------------------------- /src/Chapter15.Tests/Listing15.04.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_04.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"1 11 | 2 12 | 3 13 | 4 14 | 5 15 | 6"; 16 | 17 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 18 | expected, Program.Main); 19 | } 20 | } -------------------------------------------------------------------------------- /src/Chapter15.Tests/Listing15.06.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_06.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @""; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter15.Tests/Listing15.07.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_07.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @""; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter15.Tests/Listing15.08.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_08.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @""; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter15.Tests/Listing15.11.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_11.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Phonograph (1877) 11 | Kinetoscope (1888) 12 | Electrical Telegraph (1837) 13 | Steam Locomotive (1815)"; 14 | 15 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 16 | expected, Program.Main); 17 | } 18 | } -------------------------------------------------------------------------------- /src/Chapter15.Tests/Listing15.15.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_15.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | string expected = $@"Patent Count: 8{Environment.NewLine}Patent Count in 1800s: 4"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter15.Tests/Listing15.29.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_29.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"{ TeamName = France, Players = System.String[] } 11 | { TeamName = Italy, Players = System.String[] }"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Chapter15/Chapter15.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 15 4 | 5 | 6 | 7 | 8 | Program.cs 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/Chapter15/Listing15.03.ForeachWithArrays.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_03; 2 | 3 | using System; 4 | 5 | public class Program 6 | { 7 | public static void Main() 8 | { 9 | #region INCLUDE 10 | int[] array = new int[] { 1, 2, 3, 4, 5, 6 }; 11 | 12 | foreach(int item in array) 13 | { 14 | Console.WriteLine(item); 15 | } 16 | #endregion INCLUDE 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Chapter16.Tests/Chapter16.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 16 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Chapter16/Chapter16.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 16 4 | 5 | 6 | 7 | 8 | Program.cs 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/Chapter17.Tests/Chapter17.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 17 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Chapter17.Tests/Listing17.01.UsingList.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_01.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void UsingListOfT() 9 | { 10 | const string expected = 11 | "In alphabetical order Bashful is the first dwarf while Sneezy is the last."; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Chapter17.Tests/Listing17.03.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_03.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"private 11 | protected 12 | protected internal 13 | public"; 14 | 15 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 16 | expected, Program.Main); 17 | } 18 | } -------------------------------------------------------------------------------- /src/Chapter17.Tests/Listing17.04.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_04.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"2 11 | 2"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Chapter17.Tests/Listing17.05.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_05.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Error 11 | Warning 12 | Information 13 | Verbose"; 14 | 15 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 16 | expected, Program.Main); 17 | } 18 | } -------------------------------------------------------------------------------- /src/Chapter17.Tests/Listing17.06.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_06.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Error 11 | Warning 12 | Information 13 | Verbose"; 14 | 15 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 16 | expected, Program.Main); 17 | } 18 | } -------------------------------------------------------------------------------- /src/Chapter17.Tests/Listing17.09.SlicingWithSpan.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_09.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void DictionaryInitialization() 9 | { 10 | IntelliTect.TestTools.Console.ConsoleAssert.Execute(null, 11 | () => 12 | { 13 | Program.Main(); 14 | }); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter17.Tests/Listing17.12.DefiningAnIndexOperatorWithVariableParameters.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_12.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void IteratingABinaryTree() 9 | { 10 | const string expected = 11 | @"John Francis Fitzgerald 12 | Mary Josephine Hannon"; 13 | 14 | IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, 15 | Program.Main); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter17.Tests/Listing17.16.UsingPair.GetEnumeratorViaForeach.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_16.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Inigo 11 | Montoya"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter17.Tests/Listing17.21.UsingYieldReturnInAMethodThatReturnsIEnumberable.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_21.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Eagles 11 | Redskins"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter17/Listing17.16.UsingPair.GetEnumeratorViaForeach.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_16; 2 | 3 | using System; 4 | using Listing17_15; 5 | 6 | public class Program 7 | { 8 | public static void Main() 9 | { 10 | #region INCLUDE 11 | var fullName = new Pair("Inigo", "Montoya"); 12 | foreach(string name in fullName) 13 | { 14 | Console.WriteLine(name); 15 | } 16 | #endregion INCLUDE 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Chapter18.Tests/Chapter18.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 17 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Chapter18.Tests/Listing18.05.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_05.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void Main_WithNoParameters_DisplaysHelp() 9 | { 10 | string expected = @"True 11 | True 12 | False 13 | True"; 14 | IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, 15 | () => 16 | { 17 | Program.Main(); 18 | }); 19 | } 20 | } -------------------------------------------------------------------------------- /src/Chapter18.Tests/Listing18.06.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_06.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Type parameter: System.Int32"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter18.Tests/Listing18.16.RetrievingASpecificAttributeAndCheckingItsInitialization.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_16.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Help(?)"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter18.Tests/Listing18.24.UsingConditionalAttributeToEliminateACall.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_24.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Begin... 11 | MethodA() executing... 12 | End..."; 13 | 14 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 15 | expected, Program.Main); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter18.Tests/Listing18.29.DynamicProgrammingUsingReflection.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_29.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | string expected = $@"Hello! My name is Inigo Montoya 11 | {140.6} makes for a long triathlon."; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Chapter18.Tests/Listing18.30.RuntimeBindingToXMLElementsWithoutDynamic.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_30.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"InigoMontoya"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter18.Tests/Listing18.31.RuntimeBindingToXMLWithDynamics.Tests.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_31.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Inigo Montoya"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter18/4.0/Listing18.01.StartingMethodInSeparateThread.cs.encrypt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntelliTect/EssentialCSharp/af6e8da6480032e00fb55273a4c736be85086777/src/Chapter18/4.0/Listing18.01.StartingMethodInSeparateThread.cs.encrypt -------------------------------------------------------------------------------- /src/Chapter18/4.0/Listing18.02.ReturningAResultFromTask.cs.encrypt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntelliTect/EssentialCSharp/af6e8da6480032e00fb55273a4c736be85086777/src/Chapter18/4.0/Listing18.02.ReturningAResultFromTask.cs.encrypt -------------------------------------------------------------------------------- /src/Chapter18/4.0/Listing18.03.RegisteringForNotifactionsWithContinueWith.cs.encrypt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntelliTect/EssentialCSharp/af6e8da6480032e00fb55273a4c736be85086777/src/Chapter18/4.0/Listing18.03.RegisteringForNotifactionsWithContinueWith.cs.encrypt -------------------------------------------------------------------------------- /src/Chapter18/4.0/Listing18.05.UnhandledExceptionsUsingContinueWith.cs.encrypt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntelliTect/EssentialCSharp/af6e8da6480032e00fb55273a4c736be85086777/src/Chapter18/4.0/Listing18.05.UnhandledExceptionsUsingContinueWith.cs.encrypt -------------------------------------------------------------------------------- /src/Chapter18/4.0/Listing18.12.CancelingAParallelLoop.cs.encrypt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntelliTect/EssentialCSharp/af6e8da6480032e00fb55273a4c736be85086777/src/Chapter18/4.0/Listing18.12.CancelingAParallelLoop.cs.encrypt -------------------------------------------------------------------------------- /src/Chapter18/4.0/Listing18.13.LinqSelect.cs.encrypt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntelliTect/EssentialCSharp/af6e8da6480032e00fb55273a4c736be85086777/src/Chapter18/4.0/Listing18.13.LinqSelect.cs.encrypt -------------------------------------------------------------------------------- /src/Chapter18/4.0/Listing18.14.ParallelLinqSelect.cs.encrypt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntelliTect/EssentialCSharp/af6e8da6480032e00fb55273a4c736be85086777/src/Chapter18/4.0/Listing18.14.ParallelLinqSelect.cs.encrypt -------------------------------------------------------------------------------- /src/Chapter18/4.0/Listing18.15.ParallelLinqWithStandardQueryOperators.cs.encrypt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntelliTect/EssentialCSharp/af6e8da6480032e00fb55273a4c736be85086777/src/Chapter18/4.0/Listing18.15.ParallelLinqWithStandardQueryOperators.cs.encrypt -------------------------------------------------------------------------------- /src/Chapter18/4.0/Listing18.16.ParallelLinqWithQueryExpressions.cs.encrypt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntelliTect/EssentialCSharp/af6e8da6480032e00fb55273a4c736be85086777/src/Chapter18/4.0/Listing18.16.ParallelLinqWithQueryExpressions.cs.encrypt -------------------------------------------------------------------------------- /src/Chapter18/4.0/Listing18.18.StartingMethodUsingThread.cs.encrypt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntelliTect/EssentialCSharp/af6e8da6480032e00fb55273a4c736be85086777/src/Chapter18/4.0/Listing18.18.StartingMethodUsingThread.cs.encrypt -------------------------------------------------------------------------------- /src/Chapter18/4.0/Listing18.19.AynchronousCallsUsingThreadPool.cs.encrypt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntelliTect/EssentialCSharp/af6e8da6480032e00fb55273a4c736be85086777/src/Chapter18/4.0/Listing18.19.AynchronousCallsUsingThreadPool.cs.encrypt -------------------------------------------------------------------------------- /src/Chapter18/4.0/Listing18.20.RegisteringForUnhandledExceptions.cs.encrypt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntelliTect/EssentialCSharp/af6e8da6480032e00fb55273a4c736be85086777/src/Chapter18/4.0/Listing18.20.RegisteringForUnhandledExceptions.cs.encrypt -------------------------------------------------------------------------------- /src/Chapter18/Listing18.02.UsingTypeofToCreateASystem.TypeInstance.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_02; 2 | 3 | #region INCLUDE 4 | using System.Diagnostics; 5 | #region EXCLUDE 6 | public class Program 7 | { 8 | public static void Main() 9 | { 10 | #endregion EXCLUDE 11 | ThreadPriorityLevel priority; 12 | priority = (ThreadPriorityLevel)Enum.Parse( 13 | typeof(ThreadPriorityLevel), "Idle"); 14 | //... 15 | #endregion INCLUDE 16 | } 17 | } -------------------------------------------------------------------------------- /src/Chapter18/Listing18.04.DeclaringTheStackClass.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_04; 2 | 3 | #region INCLUDE 4 | public class Stack 5 | { 6 | //... 7 | public void Add(T i) 8 | { 9 | //... 10 | Type t = typeof(T); 11 | //... 12 | } 13 | //... 14 | } 15 | #endregion INCLUDE 16 | -------------------------------------------------------------------------------- /src/Chapter18/Listing18.12.csproj.xml: -------------------------------------------------------------------------------- 1 | #region INCLUDE 2 | 3 | 4 | Addison Wesley 5 | Copyright © Addison Wesley 2020 6 | Essential C# 8.0 7 | 8.0 8 | 9 | 10 | #endregion INCLUDE 11 | -------------------------------------------------------------------------------- /src/Chapter18/Listing18.12.csprojMockFileForResequencingListings.Placeholder.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_13; 2 | 3 | 4 | //Allows for the csproj file listing example to be accounted for when resequencing listings. just rename this 5 | // file with respect to where the csproj file examples should be placed. 6 | -------------------------------------------------------------------------------- /src/Chapter18/Listing18.13.DefiningACustomAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_13; 2 | 3 | #region INCLUDE 4 | public class CommandLineSwitchRequiredAttribute : Attribute 5 | { 6 | } 7 | #endregion INCLUDE 8 | -------------------------------------------------------------------------------- /src/Chapter18/Listing18.19.RestrictingTheConstructsAnAttributeCanDecorate.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_19; 2 | 3 | #region INCLUDE 4 | [AttributeUsage(AttributeTargets.Property)] 5 | public class CommandLineSwitchAliasAttribute : Attribute 6 | { 7 | // ... 8 | } 9 | #endregion INCLUDE 10 | -------------------------------------------------------------------------------- /src/Chapter18/Listing18.20.AttributeUsageAttributeRestrictingWhereToApplyAnAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_20; 2 | 3 | // Will not compile if uncommented 4 | /* 5 | #region INCLUDE 6 | // ERROR: The attribute usage is restricted to properties 7 | [CommandLineSwitchAlias("?")] 8 | class CommandLineInfo 9 | { 10 | } 11 | #endregion INCLUDE 12 | */ 13 | -------------------------------------------------------------------------------- /src/Chapter18/Listing18.21.LimitingAnAttributesUsageWithAttributeUsageAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_21; 2 | 3 | #region INCLUDE 4 | // Restrict the attribute to properties and fields 5 | #region HIGHLIGHT 6 | [AttributeUsage( 7 | AttributeTargets.Field | AttributeTargets.Property)] 8 | #endregion HIGHLIGHT 9 | public class CommandLineSwitchAliasAttribute : Attribute 10 | { 11 | // ... 12 | } 13 | #endregion INCLUDE 14 | -------------------------------------------------------------------------------- /src/Chapter18/Listing18.22.UsingANamedParameter.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_22; 2 | 3 | #region INCLUDE 4 | [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] 5 | public class CommandLineSwitchAliasAttribute : Attribute 6 | { 7 | // ... 8 | } 9 | #endregion INCLUDE 10 | -------------------------------------------------------------------------------- /src/Chapter18/Listing18.25.UsingObsoleteAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_25; 2 | 3 | #region INCLUDE 4 | public class Program 5 | { 6 | public static void Main() 7 | { 8 | ObsoleteMethod(); 9 | } 10 | 11 | [Obsolete] 12 | public static void ObsoleteMethod() 13 | { 14 | } 15 | } 16 | #endregion INCLUDE 17 | -------------------------------------------------------------------------------- /src/Chapter19.Tests/Chapter19.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 19 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Chapter19.Tests/Listing19.04.Test.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter19.Listing19_04.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void ObservingUnhandledExceptionsWithContinueWith() 9 | { 10 | string expected = "Task State: Completed"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, 13 | () => 14 | { 15 | Program.Main(); 16 | }); 17 | } 18 | } -------------------------------------------------------------------------------- /src/Chapter19.Tests/Listing19.06.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter19.Listing19_06.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"ERROR: Operation is not valid due to the current state of the object."; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter20.Tests/Chapter20.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/Chapter20.Tests/Listing20.07.Tests.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter20.Listing20_07.Tests; 2 | 3 | [TestClass] 4 | public class AsyncEncryptionCollectionTests 5 | { 6 | [TestMethod] 7 | public async Task MainDoesNotThrow() 8 | { 9 | await IntelliTect.TestTools.Console.ConsoleAssert.ExecuteAsync("", async () => await AsyncEncryptionCollection.Main()); 10 | } 11 | } -------------------------------------------------------------------------------- /src/Chapter20.Tests/ProgramWrapper.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter20.Tests; 2 | 3 | public class ProgramWrapper 4 | { 5 | Func MainMethod { get; } 6 | 7 | public ProgramWrapper( 8 | Func mainMethod) 9 | { 10 | MainMethod = mainMethod; 11 | } 12 | 13 | public async Task Main(string[] args) 14 | { 15 | await MainMethod(args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Chapter21.Tests/Chapter21.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/Chapter21.Tests/Listing21.01.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter21.Listing21_01.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter21.Tests/Listing21.02.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter21.Listing21_02.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter21.Tests/Listing21.04.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter21.Listing21_04.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"ERROR: AggregateException: 11 | UnauthorizedAccessException - Attempted to perform an unauthorized operation.*"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.ExpectLike( 14 | expected, Program.Main); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Chapter21/Utility.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Shared; 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | static class Utility 7 | { 8 | public static IEnumerable GetData(int count) 9 | { 10 | for(int i = 0; i < count; i++) 11 | yield return Guid.NewGuid().ToString(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Chapter22.Tests/Chapter22.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 22 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Chapter22.Tests/Listing22.04.SynchronizingWithLockKeyword.Tests.cs: -------------------------------------------------------------------------------- 1 | using static AddisonWesley.Michaelis.EssentialCSharp.Chapter22.Listing22_01.Tests.ProgramTests; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter22.Listing22_04.Tests; 4 | 5 | [TestClass] 6 | public class ProgramTests 7 | { 8 | [TestMethod] 9 | public void SynchronizedIncrementAndDecrement() 10 | { 11 | Assert.IsTrue( 12 | IsIncrementDecrementLikelySynchronized(Program.Main, short.MaxValue)); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter22.Tests/Listing22.05.AsyncMain.Tests.cs: -------------------------------------------------------------------------------- 1 | using static AddisonWesley.Michaelis.EssentialCSharp.Chapter22.Listing22_01.Tests.ProgramTests; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter22.Listing22_05.Tests; 4 | 5 | [TestClass] 6 | public class ProgramTests 7 | { 8 | [TestMethod] 9 | public void SynchronizedIncrementAndDecrement() 10 | { 11 | Assert.IsTrue(IsIncrementDecrementLikelySynchronized( 12 | (args)=>Program.Main(args).Result, short.MaxValue)); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/Chapter22.Tests/Listing22.09.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter22.Listing22_09.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"ENTER to shut down"; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter22.Tests/Listing22.11.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter22.Listing22_11.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | string expected = $@"Decrement Count = {-32767.01134} 11 | Main Count = {32767.01134}"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 14 | expected, Program.Main); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Chapter22.Tests/Listing22.12.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter22.Listing22_12.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"Decrement Count = * 11 | Main Count = *"; 12 | 13 | IntelliTect.TestTools.Console.ConsoleAssert.ExpectLike( 14 | expected, Program.Main); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Chapter23.Tests/Chapter23.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 23 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Chapter23.Tests/Listing23.17.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter23.Listing23_17.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"S5280ft = Smile "; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter23.Tests/Listing23.18.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter23.Listing23_18.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = @"S5280ft = Smile "; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter23.Tests/Listing23.19.Tests.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter23.Listing23_19.Tests; 3 | 4 | [TestClass] 5 | public class ProgramTests 6 | { 7 | [TestMethod] 8 | public void MainTest() 9 | { 10 | const string expected = "30° 18\' 0\""; 11 | 12 | IntelliTect.TestTools.Console.ConsoleAssert.Expect( 13 | expected, Program.Main); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter23/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/Chapter23/Listing23.01.DeclaringAnExternalMethod.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter23.Listing23_01; 2 | 3 | #region INCLUDE 4 | using System; 5 | using System.Runtime.InteropServices; 6 | public class VirtualMemoryManager 7 | { 8 | [DllImport("kernel32.dll", EntryPoint = "GetCurrentProcess")] 9 | #region HIGHLIGHT 10 | internal static extern IntPtr GetCurrentProcessHandle(); 11 | #endregion HIGHLIGHT 12 | } 13 | #endregion INCLUDE 14 | -------------------------------------------------------------------------------- /src/Chapter23/Listing23.10.DesignatingAMethodForUnsafeCode.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter23.Listing23_10 2 | { 3 | #region INCLUDE 4 | public class Program 5 | { 6 | static unsafe int Main(string[] args) 7 | { 8 | #region EXCLUDE 9 | return 0; 10 | #endregion EXCLUDE 11 | } 12 | } 13 | #endregion INCLUDE 14 | } -------------------------------------------------------------------------------- /src/Chapter23/Listing23.11.DesignatingACodeBlockForUnsafeCode.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter23.Listing23_11; 2 | 3 | #region INCLUDE 4 | public class Program 5 | { 6 | static int Main(string[] args) 7 | { 8 | unsafe 9 | { 10 | #region EXCLUDE 11 | return 0; 12 | #endregion EXCLUDE 13 | } 14 | } 15 | } 16 | #endregion INCLUDE 17 | -------------------------------------------------------------------------------- /src/Chapter23/Listing23.13.InvalidReferentTypeExample.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter23.Listing23_13; 2 | 3 | #region INCLUDE 4 | struct ServiceStatus 5 | { 6 | int State; 7 | string Description; // Description is a reference type 8 | } 9 | #endregion INCLUDE 10 | -------------------------------------------------------------------------------- /src/Chapter23/Listing23.15.AfixedStatementWithoutAddressOrArrayIndexer.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter23.Listing23_15; 2 | 3 | public unsafe class FixedState 4 | { 5 | public static void Main() 6 | { 7 | #region INCLUDE 8 | byte[] bytes = new byte[24]; 9 | fixed (byte* pData = bytes) 10 | { 11 | // ... 12 | } 13 | #endregion INCLUDE 14 | } 15 | } -------------------------------------------------------------------------------- /src/Chapter23/Listing23.16.AllocatingDataOnTheCallStack.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter23.Listing23_16 2 | { 3 | public static class Program 4 | { 5 | #region INCLUDE 6 | public static void Main() 7 | { 8 | unsafe 9 | { 10 | // ... 11 | byte* bytes = stackalloc byte[42]; 12 | // ... 13 | } 14 | } 15 | #endregion INCLUDE 16 | } 17 | } -------------------------------------------------------------------------------- /src/Chapter23/Program.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter21; 2 | 3 | class Program 4 | { 5 | static void Main(string[] args) 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/Modelling/13.7.sequencediagram: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /src/Modelling/13.7.sequencediagram.layout: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /src/Shared/AsyncCompletedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AddisonWesley.Michaelis.EssentialCSharp.Shared 4 | { 5 | public class AsyncCompletedEventArgs : EventArgs 6 | { 7 | public AsyncCompletedEventArgs(Exception error, bool cancelled, object userState) { } 8 | public bool Cancelled { get; } 9 | public Exception Error { get; } 10 | public object UserState { get; } 11 | protected void RaiseExceptionIfNecessary() { throw new NotImplementedException(); } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Shared/DoWorkEventArgs.cs: -------------------------------------------------------------------------------- 1 | namespace AddisonWesley.Michaelis.EssentialCSharp.Shared; 2 | 3 | public class DoWorkEventArgs : EventArgs 4 | { 5 | public DoWorkEventArgs(object argument) { Argument = argument; } 6 | public object Argument { get; } 7 | public bool Cancel { get; set; } 8 | public object? Result { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/Shared/Lib/IntelliTect.TestTools.Console.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntelliTect/EssentialCSharp/af6e8da6480032e00fb55273a4c736be85086777/src/Shared/Lib/IntelliTect.TestTools.Console.dll -------------------------------------------------------------------------------- /src/Shared/Tests/Parallel.runsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 6 | -------------------------------------------------------------------------------- /testEnvironments.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1", 3 | "environments": [ 4 | { 5 | "name": "WSL-Ubuntu", 6 | "type": "wsl", 7 | "wslDistribution": "Ubuntu" 8 | } 9 | ] 10 | } --------------------------------------------------------------------------------