J
J Miro
When I call the Generic method ShowName in the following code, I get the
error message "'T' does not contain a definition for 'Name'." Does anyone
know why? Thanks in advance. Jay.
//------------------------------------
using System;
using System.Collections.Generic;
namespace ConsoleApp1
{
class GenericsTest
{
static void Main(string[] args)
{
Person person = new Person();
person.Name = "John";
ShowName<Person>(person);
}
static void ShowName<T>(T someObject)
{
Console.WriteLine(someObject.Name);
}
}
public class Person
{
public string Name = "";
}
}
//-----------------------------------
error message "'T' does not contain a definition for 'Name'." Does anyone
know why? Thanks in advance. Jay.
//------------------------------------
using System;
using System.Collections.Generic;
namespace ConsoleApp1
{
class GenericsTest
{
static void Main(string[] args)
{
Person person = new Person();
person.Name = "John";
ShowName<Person>(person);
}
static void ShowName<T>(T someObject)
{
Console.WriteLine(someObject.Name);
}
}
public class Person
{
public string Name = "";
}
}
//-----------------------------------