vb.net - Generic Method for Numeric Types -


in vb.net if want have extension method numerical variables of different types (integer, long, decimal, double) have define multiple methods these:

<extension()> public function add(a integer, b integer) integer     return + b end function  <extension()> public function add(a long, b long) long     return + b end function  <extension()> public function add(a double, b double) double     return + b end function  <extension()> public function add(a decimal, b decimal) decimal     return + b end function 

now 1 single operation alright, more methods want create more duplicates have to, too.

is there generic way so? love see (pseudo-code):

<extension()> _ public function add(of t numeric)(a t, b t) t     return + b end function 

or there other concept doing so?

this cannot done, because cannot constrain generic type group of numeric types (integer, long, decimal, double). problem there no iarithmetic interface use constrain t to, therefore cannot write this:

' not work because iarithmetic not exist <extension()> _ public function add(of t iarithmetic)(a t, b t) t     return + b end function 

however, can join cause convince microsoft implement microsoft feedback center , proposing and/or commenting on similar requests.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -