当我们将参数声明为ICollection并将对象实例化为List时,为什么我们无法检索索引?即
ICollection<ProductDTO> Products = new List<ProductDTO>();
Products.Add(new ProductDTO(1,"Pen"));
Products.Add(new ProductDTO(2,"Notebook"));Run Code Online (Sandbox Code Playgroud)
然后,这将无效:
ProductDTO product = (ProductDTO)Products[0];Run Code Online (Sandbox Code Playgroud)
我错过了什么?
[是的,我们可以使用List作为声明,它可以工作,但我不想声明为列表,如:
List<ProductDTO> Products = new List<ProductDTO>();Run Code Online (Sandbox Code Playgroud)
]
我每天都有一个数据,有多个数据条目发生.如果我想将它显示为stackarea图表,excel会以完美的方式执行此操作,即在x轴上均匀显示日期间隔.当我尝试使用MS Charting工具执行此操作时,x轴上的间隔受条目数量的影响.03/08/10 36 94
04/08/10 26 104
04/08/10 26 104
05/08/10 28 102
05/08/10 28 102
05/08/10 35 95
05/08/10 35 95
任何想法,我怎么能告诉AxisX会有一个固定的间隔?
管道参数是否仅适用于接受一个参数的功能?如果我们看看Chris Smiths页面上的例子,
// Using the Pipe-Forward operator (|>)
let photosInMB_pipeforward =
@"C:\Users\chrsmith\Pictures\"
|> filesUnderFolder
|> Seq.map fileInfo
|> Seq.map fileSize
|> Seq.fold (+) 0L
|> bytesToMB
Run Code Online (Sandbox Code Playgroud)
他的filesUnderFolder函数只期望rootFolder参数,如果函数期望两个参数,即
let filesUnderFolder size rootFolder
然后这不起作用:
// Using the Pipe-Forward operator (|>)
let size= 4
let photosInMB_pipeforward =
@"C:\Users\chrsmith\Pictures\"
|> filesUnderFolder size
|> Seq.map fileInfo
|> Seq.map fileSize
|> Seq.fold (+) 0L
|> bytesToMB
Run Code Online (Sandbox Code Playgroud)
因为我可以定义
let inline (>>) f g x y = g(f x y)
我认为我应该能够使用具有多个输入参数的函数的管道运算符,对吧?我错过了什么?
为什么这段代码正在处理我的fsi,但无法构建项目?我正在使用vs2010和F#2.0 ......我遗漏了什么想法?
let arg = [@"C:\Temp\bin"; @"C:\temp\xml"]
arg|> List.map(fun (s) -> printfn "%s" s)
Run Code Online (Sandbox Code Playgroud)
得到错误告诉它期待int,怎么样?
Error 1
Type mismatch. Expecting a string list -> int but given a string list -> 'a list
The type 'int' does not match the type ''a list'
C:\Users\Ebru\Documents\Visual Studio 2010\Projects\WinFind\WinFind\Program.fsRun Code Online (Sandbox Code Playgroud) 我已经为我的web和Windows项目的配置文件创建了T4模板.我可以成功生成主web.config,以及其他环境的所有配置,即web.ci.config等.但是,我无法摆脱我的主tt文件上的错误,例如:
- 字符"#",十六进制值0x23在XML名称中是非法的.
- 字符'<',十六进制值0x3c在XML属性值中是非法的.
- 意外的XML声明.XML声明必须是文档中的第一个节点,并且不允许在其前面显示空白字符.
我应该错过一个xml架构或引用,但是什么?
我的文件看起来像:
<#@ template debug="true" hostSpecific="true" #>
<#@ output extension= ".config" #>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
...
<add key="FileUploadFolder" value="<#= this.FileUpload #>" />
...
</configuration>
<#+
string FileUpload="\\\\server\\folder";
#>
Run Code Online (Sandbox Code Playgroud)
这是截图
我试图通过迭代加载引用的程序集.
我加载程序集,并通过getRefs获取引用的程序集.getRefs没有任何输入参数所以它应该是val getRefs:Assembly-> AssemblyName [],但认为它是unit-> AssemblyName [],有什么想法吗?
let getreffiles (name:string) =
let loadAssembly (name:string)=
Assembly.Load(name)
let getRefs (assembly:Assembly)=
assembly.GetReferencedAssemblies
//Get the referenced assembly list and print the full name to console
name
|>loadAssembly
|>getRefs
|>List.iter (fun s ->
printfn "Referenced Assembly name %s types" s.FullName);;
Run Code Online (Sandbox Code Playgroud)
Type mismatch. Expecting a (unit -> AssemblyName []) -> 'a but given a 'b list -> unit
The type 'unit -> AssemblyName []' does not match the type ''a list'
C:\Users\Ebru\Documents\Visual Studio …Run Code Online (Sandbox Code Playgroud)