diff --git a/Nullable_types/App.config b/Nullable_types/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/Nullable_types/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Nullable_types/Nullable_types.csproj b/Nullable_types/Nullable_types.csproj new file mode 100644 index 0000000..9ca2cac --- /dev/null +++ b/Nullable_types/Nullable_types.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {9192B9D9-88CD-4A3D-B586-4DA40F0A36B8} + Exe + Nullable_types + Nullable_types + v4.6.1 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Nullable_types/Program.cs b/Nullable_types/Program.cs new file mode 100644 index 0000000..be4bbc9 --- /dev/null +++ b/Nullable_types/Program.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Nullable_types +{ + class Program + { + static void Main(string[] args) + { + //DateTime date = null; //datetime is nott nullable + + Nullable ndate = null; + DateTime? nullable_date = null; + + /* + Console.WriteLine("GetValueOrDefault(): " + nullable_date.GetValueOrDefault()); + Console.WriteLine("HasValue: " + nullable_date.HasValue); + Console.WriteLine("Value: " + nullable_date.Value); + */ + nullable_date = new DateTime(2014, 1, 1); + //DateTime date2 = nullable_date; + DateTime date2 = nullable_date.GetValueOrDefault(); + DateTime? date3 = date2; + + Console.WriteLine(date2); + Console.WriteLine(date3.GetValueOrDefault()); + + DateTime date4; + + //Method 1 + if (nullable_date != null) + date4 = nullable_date.GetValueOrDefault(); + else + date4 = DateTime.Today; + Console.WriteLine(date4); + //Method 2 + + DateTime date5 = nullable_date ?? DateTime.Today; + Console.WriteLine(date5); + + DateTime date6 = (nullable_date != null) ? nullable_date.GetValueOrDefault() : DateTime.Today; + Console.WriteLine(date6); + + } + } +} + diff --git a/Nullable_types/Properties/AssemblyInfo.cs b/Nullable_types/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..51649cd --- /dev/null +++ b/Nullable_types/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Nullable_types")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Nullable_types")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("9192b9d9-88cd-4a3d-b586-4da40f0a36b8")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TrainingAdvancedTechniques.sln b/TrainingAdvancedTechniques.sln index d70abe8..580021f 100644 --- a/TrainingAdvancedTechniques.sln +++ b/TrainingAdvancedTechniques.sln @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExtensionMethods", "Extensi EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Linq_examples", "Linq_examples\Linq_examples.csproj", "{668F191E-426E-498F-A896-A9E5215CD83E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nullable_types", "Nullable_types\Nullable_types.csproj", "{9192B9D9-88CD-4A3D-B586-4DA40F0A36B8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,6 +41,10 @@ Global {668F191E-426E-498F-A896-A9E5215CD83E}.Debug|Any CPU.Build.0 = Debug|Any CPU {668F191E-426E-498F-A896-A9E5215CD83E}.Release|Any CPU.ActiveCfg = Release|Any CPU {668F191E-426E-498F-A896-A9E5215CD83E}.Release|Any CPU.Build.0 = Release|Any CPU + {9192B9D9-88CD-4A3D-B586-4DA40F0A36B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9192B9D9-88CD-4A3D-B586-4DA40F0A36B8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9192B9D9-88CD-4A3D-B586-4DA40F0A36B8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9192B9D9-88CD-4A3D-B586-4DA40F0A36B8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE