C# Programming - Generics - Discussion
Discussion Forum : Generics - General Questions (Q.No. 2)
2.
For the code snippet shown below, which of the following statements are valid?
public class Generic<T>
{
public T Field;
public void TestSub()
{
T i = Field + 1;
}
}
class MyProgram
{
static void Main(string[] args)
{
Generic<int> gen = new Generic<int>();
gen.TestSub();
}
}
Discussion:
1 comments Page 1 of 1.
Isha Lal said:
1 decade ago
It will show a compiler error because the statement
"Field + 1" is incorrect.
Operand + is applied to 2 different datatypes, int and T.
Operand + is defined only for same datatypes.
"Field + 1" is incorrect.
Operand + is applied to 2 different datatypes, int and T.
Operand + is defined only for same datatypes.
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers