Amir Movahedi
Amir Movahedi

Reputation: 1792

Implicity generic struct dosn't work in method

1 => I use generic strut for return type method , follow code:

  public Test<User> Get()
  {

   Test<User> user = new Test<User>();
   return user;

  }

Use method:

Test<User> retUser = Get();//Implicity error can not convert User to User

2=>But in other hand :

  Test<User> user = new Test<User>();
  Test<User> user2 = user;//No error implicity Why??

What's difference between 1,2 Codes ?

Upvotes: 0

Views: 52

Answers (1)

James
James

Reputation: 9985

You most likely have 2 User classes, use the refactoring tools to rename one and you'll probably end up with either this

Test<Foo> retUser = Get();//Implicity error can not convert User to Foo

or this

Test<User> retUser = Get();//Implicity error can not convert Foo to User

You'll then need to delete/merge the 2 classes to remove the ambiguituy

Upvotes: 1

Related Questions