-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added primary constructor example (#539)
- Loading branch information
1 parent
03a877d
commit f8520e4
Showing
51 changed files
with
118 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...06.29.CallingAnObjectInitializer.Tests.cs → ...izerWithExplicitMemberAssignment.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ing06.32.OverloadingAConstructor.Tests.cs → ...ing06.33.OverloadingAConstructor.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...CallingOneConstructorFromAnother.Tests.cs → ...CallingOneConstructorFromAnother.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
....ProvidingAnInitializationMethod.Tests.cs → ....ProvidingAnInitializationMethod.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ValidationOnNon-NullableProperty.Tests.cs → ...ValidationOnNon-NullableProperty.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...henAndNotNullIfNotNullAttributes.Tests.cs → ...henAndNotNullIfNotNullAttributes.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...NullReturnWithMaybeNullAttribute.Tests.cs → ...NullReturnWithMaybeNullAttribute.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
....DefiningAndUsingADeconstructors.Tests.cs → ....DefiningAndUsingADeconstructors.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ImplicitlyInvokingDeconstructors.Tests.cs → ...ImplicitlyInvokingDeconstructors.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...sting06.46.AccessingAStaticField.Tests.cs → ...sting06.47.AccessingAStaticField.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ningAStaticMethodOnDirectoryInfo.Tests.cs → ...ningAStaticMethodOnDirectoryInfo.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...sting06.50.DeclaringAStaticClass.Tests.cs → ...sting06.51.DeclaringAStaticClass.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...AutomaticallyImplementedProperty.Tests.cs → ...AutomaticallyImplementedProperty.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...isting06.55.DefiningANestedClass.Tests.cs → ...isting06.56.DefiningANestedClass.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_26; | ||
|
||
#if NET8_0_OR_GREATER | ||
public class Program | ||
{ | ||
public static void Main() | ||
{ | ||
Employee employee = new("Inigo", "Montoya"); | ||
employee.Salary = "Too Little"; | ||
|
||
System.Console.WriteLine( | ||
$"{employee.FirstName} {employee.LastName}: {employee.Salary}"); | ||
} | ||
} | ||
|
||
#region INCLUDE | ||
#region HIGHLIGHT | ||
// Employee constructor | ||
public class Employee(string firstName, string lastName) | ||
{ | ||
public string FirstName { get; set; } = firstName; | ||
public string LastName { get; set; } = lastName; | ||
#endregion HIGHLIGHT | ||
public string? Salary { get; set; } = "Not Enough"; | ||
|
||
#region EXCLUDE | ||
public string? Title { get; set; } | ||
public Employee? Manager { get; set; } | ||
|
||
// Name property | ||
public string FullName | ||
{ | ||
get | ||
{ | ||
return FirstName + " " + LastName; | ||
} | ||
set | ||
{ | ||
// Split the assigned value into | ||
// first and last names | ||
string[] names = value.Split(' '); | ||
if(names.Length == 2) | ||
{ | ||
FirstName = names[0]; | ||
LastName = names[1]; | ||
} | ||
else | ||
{ | ||
// Throw an exception if the full | ||
// name was not assigned | ||
throw new System.ArgumentException( | ||
$"Assigned value '{ value }' is invalid", | ||
nameof(value)); | ||
} | ||
} | ||
} | ||
#endregion EXCLUDE | ||
} | ||
#endregion INCLUDE | ||
#endif // NET8_0_OR_GREATER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletions
5
...er06/Listing06.26.DefiningAConstructor.cs → ...er06/Listing06.28.DefiningAConstructor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...28.DefaultConstructorNoLongerAvailable.cs → ...29.DefaultConstructorNoLongerAvailable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...nitializerWithExplicitMemberAssignment.cs → ...nitializerWithExplicitMemberAssignment.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...isting06.30.CallingAnObjectInitializer.cs → ...isting06.31.CallingAnObjectInitializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...Chapter06/Listing06.31.InitOnlySetters.cs → ...Chapter06/Listing06.32.InitOnlySetters.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...06.33.CallingOneConstructorFromAnother.cs → ...06.34.CallingOneConstructorFromAnother.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...g06.34.ProvidingAnInitializationMethod.cs → ...g06.35.ProvidingAnInitializationMethod.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...vidingValidationOnNon-NullableProperty.cs → ...vidingValidationOnNon-NullableProperty.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...TypeAutomaticallyImplementedProperties.cs → ...TypeAutomaticallyImplementedProperties.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...pter06/Listing06.37.RequiredProperties.cs → ...pter06/Listing06.38.RequiredProperties.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...uiredMembersWithinTheObjectInitializer.cs → ...uiredMembersWithinTheObjectInitializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
....DisablingRequiredObjectInitialization.cs → ....DisablingRequiredObjectInitialization.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tNullWhenAndNotNullIfNotNullAttributes.cs → ...tNullWhenAndNotNullIfNotNullAttributes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...entialNullReturnWithMaybeNullAttribute.cs → ...entialNullReturnWithMaybeNullAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...g06.42.DefiningAndUsingADeconstructors.cs → ...g06.43.DefiningAndUsingADeconstructors.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...06.43.ImplicitlyInvokingDeconstructors.cs → ...06.44.ImplicitlyInvokingDeconstructors.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...r06/Listing06.44.DeclaringAStaticField.cs → ...r06/Listing06.45.DeclaringAStaticField.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
....45.AssigningAStaticFieldAtDeclaration.cs → ....46.AssigningAStaticFieldAtDeclaration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...r06/Listing06.46.AccessingAStaticField.cs → ...r06/Listing06.47.AccessingAStaticField.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...7.DefiningAStaticMethodOnDirectoryInfo.cs → ...8.DefiningAStaticMethodOnDirectoryInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...sting06.48.DeclaringAStaticConstructor.cs → ...sting06.49.DeclaringAStaticConstructor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.