Skip to content

Commit a1ce371

Browse files
authored
0402 (#77)
* Initial demos * After demo
1 parent c36d1ae commit a1ce371

File tree

6 files changed

+176
-0
lines changed

6 files changed

+176
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.6.30114.105
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sample", "sample\sample.csproj", "{54997B90-2AA1-4ACD-92EE-E5C33BE163AA}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Debug|x64 = Debug|x64
12+
Debug|x86 = Debug|x86
13+
Release|Any CPU = Release|Any CPU
14+
Release|x64 = Release|x64
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{54997B90-2AA1-4ACD-92EE-E5C33BE163AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{54997B90-2AA1-4ACD-92EE-E5C33BE163AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{54997B90-2AA1-4ACD-92EE-E5C33BE163AA}.Debug|x64.ActiveCfg = Debug|Any CPU
24+
{54997B90-2AA1-4ACD-92EE-E5C33BE163AA}.Debug|x64.Build.0 = Debug|Any CPU
25+
{54997B90-2AA1-4ACD-92EE-E5C33BE163AA}.Debug|x86.ActiveCfg = Debug|Any CPU
26+
{54997B90-2AA1-4ACD-92EE-E5C33BE163AA}.Debug|x86.Build.0 = Debug|Any CPU
27+
{54997B90-2AA1-4ACD-92EE-E5C33BE163AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{54997B90-2AA1-4ACD-92EE-E5C33BE163AA}.Release|Any CPU.Build.0 = Release|Any CPU
29+
{54997B90-2AA1-4ACD-92EE-E5C33BE163AA}.Release|x64.ActiveCfg = Release|Any CPU
30+
{54997B90-2AA1-4ACD-92EE-E5C33BE163AA}.Release|x64.Build.0 = Release|Any CPU
31+
{54997B90-2AA1-4ACD-92EE-E5C33BE163AA}.Release|x86.ActiveCfg = Release|Any CPU
32+
{54997B90-2AA1-4ACD-92EE-E5C33BE163AA}.Release|x86.Build.0 = Release|Any CPU
33+
EndGlobalSection
34+
EndGlobal
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
3+
namespace sample {
4+
5+
public class ValueTypes {
6+
7+
public static void Defaults() {
8+
9+
int? i = null; //default(int);
10+
11+
Console.WriteLine($"Default {i?.GetType().Name}: {i + 100}");
12+
13+
}
14+
15+
public static void Arrays() {
16+
17+
var values = new string[3];
18+
string firstValue = values[0];
19+
Console.WriteLine(firstValue.ToLower());
20+
21+
}
22+
23+
}
24+
25+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
3+
namespace sample
4+
{
5+
6+
// #nullable enable
7+
8+
public static class ReferenceTypes {
9+
10+
public static void SimpleNull() {
11+
12+
Hat myHat = new Hat();
13+
14+
Console.WriteLine($"MyHat is a: {myHat.GetType().Name} and {myHat}");
15+
16+
}
17+
18+
public static void Property() {
19+
20+
var myHat = new Hat();
21+
22+
Console.WriteLine($"MyHat's name is {myHat.AcquiredYear.GetType().Name}: {myHat.AcquiredYear.ToString()}");
23+
24+
}
25+
26+
public static void NullForgiving() {
27+
28+
var myHat = Find();
29+
30+
Console.WriteLine($"myHat is named {myHat!.Name}");
31+
32+
}
33+
34+
private static Hat Find() {
35+
return new Hat();
36+
}
37+
38+
}
39+
40+
// #nullable restore
41+
42+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace sample
4+
{
5+
6+
// #nullable enable
7+
8+
public class Hat {
9+
10+
[Required]
11+
public string Name { get; set; } = string.Empty;
12+
13+
public int AcquiredYear { get; set; }
14+
15+
public string Theme { get; set; } = string.Empty;
16+
17+
}
18+
19+
20+
public class Foo
21+
{
22+
23+
public static void Bar()
24+
{
25+
26+
Hat? hat = new();
27+
//hat.Name = null;
28+
29+
}
30+
31+
}
32+
// #nullable restore
33+
34+
35+
public class Customer
36+
{
37+
38+
39+
public string TaxClassification { get; set; } = "Exempt";
40+
41+
}
42+
43+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
3+
namespace sample
4+
{
5+
class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
10+
// ValueTypes.Defaults();
11+
12+
// ValueTypes.Arrays();
13+
14+
// ReferenceTypes.SimpleNull();
15+
16+
//ReferenceTypes.Property();
17+
18+
ReferenceTypes.NullForgiving();
19+
20+
}
21+
}
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
8+
</PropertyGroup>
9+
10+
</Project>

0 commit comments

Comments
 (0)