Field 'xyz' is never assigned -> structs

Thread is closed for posting
2 posts, 0 answers
  1. Wolfgang
    Wolfgang avatar
    98 posts
    Member since:
    Oct 2012

    Posted 19 Jul 2013 Link to this post

    i have the follwoing interesting issue:
    if i use a struct, i get a warningthat the field is never assigned.


    public struct Test
        public int Prop1 { get; set; }
    class Program
        private static Test test1; // Justcode warning: Field 'xyz' is never assigned
        static void Main(string[] args)
            test1.Prop1 = 1;

    if i change "private static Test test1;" to "public static Test test1;"the warning goes away.

    Why do I get the warning? The struct has no ctor. I could put a new call in the file so that the warning goes away "test1 = new Test();" .

    But why should it be needed? And why shouldn't it be needed if the field is public instead of private?

    Best regards,
  2. Zdravko
    Zdravko avatar
    657 posts

    Posted 23 Jul 2013 Link to this post

    Hello Wolfgang,

     Thanks for reporting.
    Indeed this is a bug and we have plans to remove the warning for struct types. It is already logged in our product backlog and a fix awaits.
    Thank you.

    Share what you think about JustCode with us, so we can help you even better! You can use the built-in feedback tool inside JustCode, our forum, or our JustCode feedback portal.
Back to Top