-2

I would like to pass variable type of var to method, where var is some distribution

For example:

var t = new Chi(Double.Parse(textBox8.Text));
var t = new Cauchy(Double.Parse(textBox6.Text), Double.Parse(textBox7.Text));

and method:

drawDensity(var t) {...t.Sample()..t.Density()..} 
Saverio Terracciano
  • 3,885
  • 1
  • 30
  • 42
Gugu
  • 17
  • 1
  • 8

1 Answers1

1

First, the var is not a type.It is a way to tell the compiler to infer the type for you,instead of stating it explicitly.So specifying it as a parameter type is invalid.

Secondly, drawDensity method should take a parameter that is a common type between Chi and Chaucy, for example a common interface or a base class.If you want to pass both types to your method that is the preferred way.

If there is no common type that both type implements then it should be object or dynamic.

Further reading

Selman Genç
  • 100,147
  • 13
  • 119
  • 184