在C#中是否有类似Arduino的map的功能?
答案 0 :(得分:17)
您可以使用Extension Method(例如decimal
):
public static class ExtensionMethods
{
public static decimal Map (this decimal value, decimal fromSource, decimal toSource, decimal fromTarget, decimal toTarget)
{
return (value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
}
}
然后你就可以使用它:
decimal res = 2.Map(1, 3, 0, 10);
// res will be 5
答案 1 :(得分:0)
INSERT
{
?s ?p ?o2
}
WHERE
{
?s ?p ?o .
FILTER (regex(str(?s), "iso-693") || regex(str(?o), "iso-693"))
BIND(REPLACE(?o, "iso-693", "iso-639", "i") AS ?o2) .
}