using a List<> object in an abstract class
-
Make your class generic
Giorgi Dalakishvili #region signature my articles #endregion
-
beautiful. Just went to MSDN and gave myself a quick lesson in genericmethods, and now I'm cooking with gas. Thank you!
______________________ Mr Griffin, eleventy billion is not a number...:wtf:
You are welcome :)
Giorgi Dalakishvili #region signature my articles #endregion
-
You are welcome :)
Giorgi Dalakishvili #region signature my articles #endregion
I have another one for you if you are interested. Same abstract class, i have a Get() method. Similar problem, only rather than returning a List<> object, it is for individual objects, so class one would be public override int Get(), class 2 public override string Get(), etc.
______________________ Mr Griffin, eleventy billion is not a number...:wtf:
-
I have another one for you if you are interested. Same abstract class, i have a Get() method. Similar problem, only rather than returning a List<> object, it is for individual objects, so class one would be public override int Get(), class 2 public override string Get(), etc.
______________________ Mr Griffin, eleventy billion is not a number...:wtf:
You can use T as a return type of the Get() method
Giorgi Dalakishvili #region signature my articles #endregion
-
You can use T as a return type of the Get() method
Giorgi Dalakishvili #region signature my articles #endregion
Thank you again. :) I have actually worked with these before, but that was a project for another company, 6 months ago, so I was having a hard time remembering the details :) You are a life saver (and a time saver)
______________________ Mr Griffin, eleventy billion is not a number...:wtf:
-
Thank you again. :) I have actually worked with these before, but that was a project for another company, 6 months ago, so I was having a hard time remembering the details :) You are a life saver (and a time saver)
______________________ Mr Griffin, eleventy billion is not a number...:wtf:
Thanks man :)
Giorgi Dalakishvili #region signature my articles #endregion
-
Thanks man :)
Giorgi Dalakishvili #region signature my articles #endregion
I have moved on to another class inheriting this class, and have found a new problem. here is my code:
public abstract List<T> GetList<T>() where T : Class1,new();
here is my issue. now i am trying to use the same abstract class to make another class, so this one would need to look like:public abstract List<T> GetList<T>() where T : Class2,new();
however, i cant have them both in the same abstract class, and i cant seem to figure out how to do essentially this (i know this here doesnt work):public abstract List&lt;T&gt; GetList&lt;T&gt;() where T : (CLass1,Class2),new();
Any ideas?______________________ Mr Griffin, eleventy billion is not a number...:wtf:
-
I have moved on to another class inheriting this class, and have found a new problem. here is my code:
public abstract List<T> GetList<T>() where T : Class1,new();
here is my issue. now i am trying to use the same abstract class to make another class, so this one would need to look like:public abstract List<T> GetList<T>() where T : Class2,new();
however, i cant have them both in the same abstract class, and i cant seem to figure out how to do essentially this (i know this here doesnt work):public abstract List&lt;T&gt; GetList&lt;T&gt;() where T : (CLass1,Class2),new();
Any ideas?______________________ Mr Griffin, eleventy billion is not a number...:wtf:
As you know C# does not support multiple inheritance of implementation so at most one base class can be used in a constraint. Just read the documentation: An Introduction to C# Generics[^]
Giorgi Dalakishvili #region signature my articles #endregion
-
As you know C# does not support multiple inheritance of implementation so at most one base class can be used in a constraint. Just read the documentation: An Introduction to C# Generics[^]
Giorgi Dalakishvili #region signature my articles #endregion
Hmmm.... I will need to figure out another way. maybe i should not be bothering to include it in the bastract class, for now. this is my project and i am the architect and sole programmer,so it should not be thta big a deal. Thank you again for all of your help. :)
______________________ Mr Griffin, eleventy billion is not a number...:wtf:
-
Hmmm.... I will need to figure out another way. maybe i should not be bothering to include it in the bastract class, for now. this is my project and i am the architect and sole programmer,so it should not be thta big a deal. Thank you again for all of your help. :)
______________________ Mr Griffin, eleventy billion is not a number...:wtf:
If you want your T parameter to inherit from Class1 and Class2 it means that either Class1 must inherit from Class2 or Class2 from Class1. In either cases you will need to specify just one class as a base class in constraint list as it will automatically mean that T inherits from the second class too.
Giorgi Dalakishvili #region signature my articles #endregion