Resharper is showing this warning: "value assigned is not used in any execution path" when I write the following code:
List<obj> testObj = new List<obj>();
testObj = testMethod();
Here testMethod()
returns type List<obj>
. However when I directly assign the testMethod()
without instantiating it, I don't get the warning.
List<obj> testObj = testMethod();
Forgive me for my ignorance, if I am missing the basics but I'm not following how the compiler allocates memory for testObj
without instantiating it.
One of the posts refers to similar question: C# Is this initialiser really redundant? but I don't find any answer to my question, as to where the testObj
variable is storing the value it received from testMethod
? Unlike primitive data types, 'object types' can store value only after they are instantiated. Please let me know, if I am missing something.