Karan Thakkar

Karan Thakkar

  • 1.5k
  • 204
  • 90.1k

How to pass generic object as parameter in c#?

Sep 12 2019 11:55 PM
I wan to call a method from two diffrent method, but the object which I want to pass is different in both the methods. lets assume an example below.
 
Public string GetCarDetails(Car carObj)
{
 string price=GetCarPrice(carObj);
return price; 
 
Public string GetBikePrice(Bike bikeObj)
{
VechileDetails obj = new VechileDetails()
string price=obj.GetBikePrice(bikeObj); 
return  price;
}
 
I want to create GetBikePrice method in VechileDetails class which can accept both the object car and bike.
I hope you guys got my problem.
Thanks. 
 
 

Answers (4)