我有类似的东西:
object[] parameter = new object[1];
parameter[0] = x;
object instantiatedType =
Activator.CreateInstance(typeToInstantiate, parameter);
Run Code Online (Sandbox Code Playgroud)
和
internal class xxx : ICompare<Type>
{
private object[] x;
# region Constructors
internal xxx(object[] x)
{
this.x = x;
}
internal xxx()
{
}
...
}
Run Code Online (Sandbox Code Playgroud)
我得到:
抛出异常:System.MissingMethodException:找不到类型为"xxxx.xxx"的构造函数..
有任何想法吗?
我开始感兴趣,并没有在一个地方找到相应术语的列表:
Map <-> Morphism
Foldable <-> Catamorphism
...
谁可以补充术语列表
List.collect是LINQ List.SelectMany的等价物吗?
[1;2;3;4] |> List.collect (fun x -> [x * x]) // [1;4;9;16]
Run Code Online (Sandbox Code Playgroud)
在LINQ
new List<int>() { 1, 2, 3, 4 }
.SelectMany(x => new List<int>() { x * x }); // 1;4;9;16
Run Code Online (Sandbox Code Playgroud)
编辑:
更合适的例子
let list1 = [1;2;3;4]
let list2 = [2;4;6]
// [2; 4; 6; 4; 8; 12; 6; 12; 18; 8; 16; 24]
list1 |> List.collect (fun a -> list2 |> List.map (fun b -> a * b))
Run Code Online (Sandbox Code Playgroud)
...
var list1 = new List<int>() { 1, 2, …Run Code Online (Sandbox Code Playgroud) 我们有一个经过Windows身份验证的WCF服务.绑定配置如下.
<basicHttpBinding>
<binding textEncoding="utf-8" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
Run Code Online (Sandbox Code Playgroud)
我试图从测试应用程序调用该服务,因为,
try
{
BasicHttpBinding binding = new BasicHttpBinding();
binding.ReceiveTimeout = new TimeSpan(10, 10, 00);
binding.SendTimeout = new TimeSpan(10, 10, 00);
binding.MaxReceivedMessageSize = Int32.MaxValue;
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
EndpointAddress endpoint = new EndpointAddress("ServiceUrl");
ChannelFactory<ICRMConnectorService> channelFactory = new ChannelFactory<ICRMConnectorService>(binding, endpoint);
channelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
var service = channelFactory.CreateChannel();
service.TestMethod();
}
catch (Exception ex)
{
throw ex;
}
Run Code Online (Sandbox Code Playgroud)
该调用返回错误,因为远程服务器返回错误:(401)未经授权.
有人可以帮忙吗?
我有两个接口:
public interface IDbModel {}
public interface IDmModel {}
Run Code Online (Sandbox Code Playgroud)
和派生自这的类:
public class DbModel : IDbModel {}
public class DmModel : IDmModel {}
public class Middle { }
Run Code Online (Sandbox Code Playgroud)
另外我有两个限制接口:
public interface IRule { }
public interface IRule<in TInput, out TOutput> : IRule
where TInput : IDmModel
where TOutput : IDbModel
{
TOutput Apply(TInput elem);
}
Run Code Online (Sandbox Code Playgroud)
从这个接口派生出一个抽象类:
public abstract class Rule<TDmModel, TMiddle, TDb> : IRule<TDmModel, TDb>
where TDmModel : IDmModel
where TDb : IDbModel
{
private readonly Func<TDmModel, TMiddle> _rule;
protected Rule(Func<TDmModel, …Run Code Online (Sandbox Code Playgroud) 我知道这里有一个类似的问题,但我希望看到一个例子,它清楚地表明,你不能做什么,interface可以使用Type Class
为了比较,我将给你一个示例代码:
class Eq a where
(==) :: a -> a -> Bool
instance Eq Integer where
x == y = x `integerEq` y
Run Code Online (Sandbox Code Playgroud)
C#代码:
interface Eq<T> { bool Equal(T elem); }
public class Integer : Eq<int>
{
public bool Equal(int elem)
{
return _elem == elem;
}
}
Run Code Online (Sandbox Code Playgroud)
如果没有正确理解,请纠正我的例子
我试图理解为什么这个linq不编译(fundInvoices不可见):
Dictionary<Fund, IEnumerable<Invoice>> paidfundInvoices;
...
from fundInvoices in paidfundInvoices
from p in fundInvoices.Value
group p by p.VendorId into ps
select new Payment
{
FundId = fundInvoices.Key.FundId, // ERROR here
Value = ps.Sum(p => p.Amount)
}
Run Code Online (Sandbox Code Playgroud)
所以我继续将其更改为匿名类型用法,并且基金发票在这里神奇可见:
from fundInvoices in paidfundInvoices
select new
{
Fund = fundInvoices.Key,
Payments = from p in fundInvoices.Value
group p by p.VendorId into ps
select new Payment
{
FundId = fundInvoices.Key.FundId, // NO ERROR
Value = ps.Sum(p => p.Amount)
}
};
Run Code Online (Sandbox Code Playgroud)
但是这种匿名类型似乎是多余的,我没有使用它.我只需要一个 …
我有string"DBCA"并希望在F#中对它进行排序
let sortedString str =
...
printfn "%A" <| sortedString "DBCA" // "ABCD"
Run Code Online (Sandbox Code Playgroud)
C#上的代码示例
String
.Concat(
_str
.OrderBy(ch => ch)
);
Run Code Online (Sandbox Code Playgroud) 在Haskell中,我们可以编写如下代码:
// (<*>) :: Applicative f => f (a -> b) -> f a -> f b
// const :: a -> b -> a
// id :: b -> b
let id = const <*> const
Run Code Online (Sandbox Code Playgroud)
如何在F#中做同样的事情?
我尝试编写类似这样的代码,但它不一样
let ( <*> ) f v =
match v with
| Some v' ->
match f with
| Some f' -> Some (f' v')
| _ -> None
| _ -> None
let cnst a _ = a
let id = …Run Code Online (Sandbox Code Playgroud)