C#: "field is not assigned to" warning

Post a reply

Confirmation code
Enter the code exactly as it appears. All letters are case insensitive.
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review

Expand view Topic review: C#: "field is not assigned to" warning

C#: "field is not assigned to" warning

Post by Miguel7 » 07 Sep 2017, 14:45

Hey guys, newbie question here: I've got a class with a property that is an instance of another class. That other class has no parameters in its constructor (and really, no constructor at all) but I'm getting this ridonkulous message saying the property is never assigned too, will always be null, and Kiss My Bits. :P

Here's the code:

Code: [Select all] [Expand]GeSHi © Codebox Plus

My best guess is that it has something to do with access modifiers ("internal" vs. "public") but that's not the error I'm getting. And to add to the mystery, the error makes no sense whatsoever - at least, not from my (admittedly human) perspective; obviously there's a blatant mistake in the Oz-like world the compiler lives in. Never assigned to? Isn't the NEW on the SAME LINE assigning it??? I must be missing something stupidly simple, because hair-jerkers like this are never half as complicated as they seem.