Your approach is not how you handle stuff like this in statically typed languages such as C#. You can only access properties / fields that are declared on the specific type. And object does not have a public field or property called id.
There are some ways around this: One would be having a base class that has an id property from which your other classes could inherit:
public class IdHolder
{
public int Id { get; set; }
}
public class Person : IdHolder
{
// Person inherits the 'Id' property from IdHolder
// other properties unique to person...
}
IdHolder could just as well be an interface or an abstract class - it depends on your specific use case (note that you would have to implement the Id property in each implementing class if you'd chose to make IdHolder an interface).
If you chose to have a base class (or interface, ...) you'd change your method to accept that as a parameter:
public static int getNextId(List<IdHolder>param)
{
int lastId = param[param.Count - 1].Id;
if (lastId!=0)
{
return lastId++;
}
return 0;
}
Another - slightly dirty - option is to use reflection. As I don't think that this is a sensible route for you to take, I won't go further into this here.
I'd advise you to have a look at an intro book into C# as there are some other aspects of your code that don't really follow C# guidelines (e. g. using camelCase instead of PascalCase).