This line:
private dynamic defaultReminder = reminder.TimeSpanText[TimeSpan.FromMinutes(15)];
You cannot use an instance variable to initialize another instance variable. Why? Because the compiler can rearrange these – there is no guarantee that reminder
will be initialized before defaultReminder
, so the above line might throw a NullReferenceException
.
Instead, just use:
private dynamic defaultReminder = TimeSpan.FromMinutes(15);
Alternatively, set up the value in the constructor:
private dynamic defaultReminder; public Reminders() { defaultReminder = reminder.TimeSpanText[TimeSpan.FromMinutes(15)]; }
There are more details about this compiler error on MSDN – Compiler Error CS0236.
Related Posts:
- How can I parse JSON with C#?
- What is IP address ‘::1’?
- What is the yield keyword used for in C#?
- Join/Where with LINQ and Lambda
- C# compiler error: “not all code paths return a value”
- How to use SQLite in Visual Studio 2017?
- C# equivalent of C++ map
- The page was not displayed because the request entity is too large on IIS
- Export Pervasive to MySQL (C#)
- Why use the params keyword?
- What does plus equals(+=) operator means here?
- The request was aborted: Could not create SSL/TLS secure channel
- finding the maximum length of lists in c#
- foreach vs someList.ForEach(){}
- The located assembly’s manifest definition does not match the assembly reference
- LEFT OUTER JOIN in LINQ
- OnTriggerEnter not working at Unity3D
- The requested resource does not support HTTP method ‘GET’
- How can I find a specific element in a List
? - Rename a file in C#
- What does mscorlib stand for?
- What is the best way to iterate over a dictionary?
- What is and how to fix System.TypeInitializationException error?
- How to move 2D Object with WASD in Unity
- The Object you want to instantiate is null. Unity 3D
- Convert date yyyyMMdd to system.datetime format
- How to bind a model to a kendo Combobox in order to use the models validatation?
- HttpWebRequest-The remote server returned an error: (400) Bad Request
- MSHTML DLL on Windows 10
- Adding values to a C# array
- Adding values to a C# array
- What does {0} mean when found in a string in C#?
- How to use html.ValidationMessageFor
- EF 5 Enable-Migrations : No context type was found in the assembly
- What does the @ symbol before a variable name mean in C#?
- What is the C# version of VB.net’s InputDialog?
- Visual studio 2019 freezes when debugging
- How to make an HTTP POST web request
- How to add comments into a Xaml file in WPF?
- Are 2 dimensional Lists possible in c#?
- Passing just a type as a parameter in C#
- How to easily initialize a list of Tuples?
- How to stop C# console applications from closing automatically? [duplicate]
- Can I send SMS Messages from a C# Application?
- How do you sort a dictionary by value?
- EntityType has no key defined error
- How do I restart my C# WinForm Application?
- regular expression “.*[^a-zA-Z0-9_].*”
- Sharing violation IOException while reading and writing to file C#
- How to delete object?
- WSACancelBlockingCall exception
- Carriage return and Line feed… Are both required in C#?
- Padding is invalid and cannot be removed?
- Inconsistent Accessibility: Parameter type is less accessible than method
- Why is it that “No HTTP resource was found that matches the request URI” here?
- How to get correct timestamp in C#
- Cannot implicitly convert type ‘int’ to ‘string’ C# class
- If a folder does not exist, create it
- C# “No suitable method found to override.” — but there is one
- System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
- What is the purpose of global.asax in asp.net
- How to convert datetime format to date format in crystal report using C#?
- How to add a string to a string[] array? There’s no .Add function
- How to block until an event is fired in c#
- How to use WPF Background Worker
- Case insensitive ‘Contains(string)’
- How to catch all exceptions in c# using try and catch?
- Getting “Handshake failed…unexpected packet format” when using WebClient.UploadFile() with “https” when the server has a valid SSL certificate
- Most efficient way to remove special characters from string
- Receiving access denied error from Visual Studio when trying to change target framework
- How to force garbage collector to run?
- Page vs Window in WPF?
- CS1617: Invalid option ‘6’ for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default
- Sort list by field (C#)
- How to post data to specific URL using WebClient in C#
- Value does not fall within the expected range
- The type or namespace name could not be found
- How to execute a stored procedure within C# program
- The remote server returned an error: (405) Method Not Allowed. WCF REST Service
- TTS Voices for Windows7 64 bits
- How to play a sound in C#, .NET
- How can I delete a file that is in use by another process?
- Convert SQL to LINQ Query
- How to resolve file being used by another process?
- How to crop an image using C#?
- Convert double to float by cast or Convert.ToSingle()?
- Call a stored procedure with parameter in c#
- Type Checking: typeof, GetType, or is?
- How do you wait for input on the same Console.WriteLine() line?
- C# Macro definitions in Preprocessor
- Adding images to buttons from Imagelist on a toolstrip?
- Multiple cases in switch statement
- System.ArgumentNullException: Value cannot be null. Parameter name: source
- Sequence contains more than one element
- Drawing circles with System.Drawing
- Parser Error Message: Could not load type ‘sometype’
- Func vs. Action vs. Predicate [duplicate]
- Cannot declare instance members in a static class in C#
- the source file is different from when the module was built
- How to convert HTML to PDF using iTextSharp