简体   繁体   中英

calling Extention Method with 'this double' in C#

im converting string to code for runtime compile using code dom, so i really need to know if its possible to call static method with 'this double', before i manage to write more complex code to produce correct string

i have method

public static double Test(this double x)
{
   //some code here...
}

and i want to call it like

double d = 5.Test();//Compiler Error: Cannot resolve symbol Test

i know this is possible for strings but i cant do the same thing for double. how can i do this also if its not possible why its possible for string? thanks for help.

declare your 5 as a double, right now it's an integer.

double d = 5D.Test();

Here's the list of numeric suffixes C# uses.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM