Is there a possibility to pass object in c# the same way as I can do it in Javascript in generic way? How can I achieve this in c#? Since all variables need to be declared but they have different class names.
class human {
constructor() {
this.name = "John";
}
}
class cat {
constructor() {
this.name = "Garfield";
}
}
function showName(character) {
console.log("My name is: " + character.name)
};
var character1 = new cat();
var character2 = new human();
showName(character1)
showName(character2)
I want to make same showName as one function but c# require to declare class names like:
public void ShowName(Human human) {}
public void ShowName(Cat cat) {}
How will look example code that I can achieve this in c# like in JS?