Below is a sample sourecode demonstrates creating Nullable Struct in C#.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { internal struct Movie { public string Name { get; set; } public string Actor { get; set; } } internal class Program { // Abundantcode - Demonstrate Nullable Struct private static void Main(string[] args) { Movie NormalMovie = new Movie { Actor = "Actor1", Name = "Movie1" }; Movie? NullableMovie = new Movie(); Console.WriteLine("Nomal Movie: " + NormalMovie.Name); Console.WriteLine("Nomal Actor : " + NormalMovie.Actor); Console.WriteLine("Nullable Movie ", NullableMovie.Value.Name); Console.ReadLine(); } } }
Leave a Reply