0

Hey guys,

I'm hoping you could explain why this doesnt work:

main file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TemplateApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            Class1<int> cl = new Class1<int>();
        }
    }
}

another template class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TemplateApplication
{
    class Class1<T>
    {
        T t;
  

        public T getValue()
        {
            return t;
        }
    }
}

Now why does it generate the following warning?

Warning 1 Field 'TemplateApplication.Class1<T>.t' is never assigned to, and will always have its default value C:\Users\John\Documents\Visual Studio 2008\Projects\TemplateApplication\TemplateApplication\Class1.cs 10 11 TemplateApplication

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Acidburn
0

It generates the warning for the exact reason stated. You never assign a value to the member variable t. If you change the line T t; to T t = new T(); then it should work.

0

idiotic me! It needed a constructor. Man can't beleive i overlooked that.

Cheers for your help btw

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.