Replace is for strings
new Random().NextDouble().ToString().Replace( . . .
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I tried to call extension string extension function , if not in delegatefunction it works well, but
in delegate function can't call extension method
then how to call extension method in delegate function?
Replace is for strings
new Random().NextDouble().ToString().Replace( . . .
ah sorry i found a why it is not worked but i don't have further idea how i can solve it
"jQuery" + ((func2_version + new Random().NextDouble())).replace(new RegExp("\D", "g"), "");
in here func2_version is dynamic type ,
runtimebinder knew (func2_version+new Random().NextDoube()) is type of string
but it is strangely can't find string's extension method
if I specify string type cast it works .....
"jQuery" + ((string)(func2_version + new Random().NextDouble())).replace(new RegExp("\D", "g"), "");
but I want a way of not specifying cast
The compiler needs to know the datatype of a variable to pick the proper class extension. The point of a dynamic is the datatype is not known to runtime. This means you can not use a string extension on a dynamic.
As your replace extension method only works if the dynamic is a string (otherwise it throws an error), you should be able cast.
A better solution is to convert the result of the + operation to a string
"jQuery" + (func2_version + new Random().NextDouble()).ToString().replace(new RegExp("\\D", "g"), "");