为什么禁止Extension Method用ref修饰符调用?
这个是可能的:
public static void Change(ref TestClass testClass, TestClass testClass2)
{
testClass = testClass2;
}
Run Code Online (Sandbox Code Playgroud)
这不是:
public static void ChangeWithExtensionMethod(this ref TestClass testClass, TestClass testClass2)
{
testClass = testClass2;
}
Run Code Online (Sandbox Code Playgroud)
但为什么?
我想为一些泛型类创建很多扩展方法,例如
public class SimpleLinkedList<T> where T:IComparable
Run Code Online (Sandbox Code Playgroud)
我已经开始创建这样的方法:
public static class LinkedListExtensions
{
public static T[] ToArray<T>(this SimpleLinkedList<T> simpleLinkedList) where T:IComparable
{
//// code
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我试图使LinkedListExtensions类像这样通用时:
public static class LinkedListExtensions<T> where T:IComparable
{
public static T[] ToArray(this SimpleLinkedList<T> simpleLinkedList)
{
////code
}
}
Run Code Online (Sandbox Code Playgroud)
我得到"扩展方法只能在非泛型,非嵌套的静态类中声明".
而我正在试图猜测这种限制来自哪里并且没有任何想法.
编辑:仍然没有明确的问题愿景.似乎这只是因为某种原因没有实现.
是否存在用于Visual Studio 2008/2010的Visual Haskell?或者尝试它的替代方案是什么?
编辑:我有很多选择,但似乎现在没有Visual Haskell.
我现在正在研究字符串搜索算法,并想知道.NET String.Contains函数用于什么算法.Reflector显示使用了这个函数,但我不知道它的名字是什么意思.
private static extern int InternalFindNLSStringEx(IntPtr handle, string localeName, int flags, string source, int sourceCount, int startIndex, string target, int targetCount);
Run Code Online (Sandbox Code Playgroud) 我的WPF应用程序在许多机器上运行良好,但现在我在用户机器上收到有关此错误的报告:
Description:
Stopped working
Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01: mysoftware.exe
Problem Signature 02: 1.0.0.1
Problem Signature 03: 4bbcd9d9
Problem Signature 04: PresentationFramework
Problem Signature 05: 3.0.0.0
Problem Signature 06: 4a174fbc
Problem Signature 07: 624f
Problem Signature 08: e1
Problem Signature 09: System.Windows.Markup.XamlParse
OS Version: 6.1.7600.2.0.0.256.48
Locale ID: 1033
Run Code Online (Sandbox Code Playgroud)
我试图使用Application DispatcherUnhandledException捕获Exception,但这没有帮助.并且在try/catch块中也翘曲Window1构造函数..NET Framework 3.5安装在该计算机上.
如何找出崩溃的原因:记录此错误,调试,......?
我正在尝试使用Watin进行测试.我需要获得具有特定属性的元素列表,例如具有"Go"标题的所有链接.
我在尝试这个:
browser.Link(link => link.Text == "Go");
Run Code Online (Sandbox Code Playgroud)
但它只返回一个元素.我也是这样想的:
var links = from link in browser.Elements
where link.Text == "Go"
select link;
Run Code Online (Sandbox Code Playgroud)
但这没有任何回报.
我试图用表达式解析价值15,270.75美元的价值
double cost = 0;
double.TryParse("$15,270.75", NumberStyles.AllowThousands | NumberStyles.AllowCurrencySymbol | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out cost);
Run Code Online (Sandbox Code Playgroud)
但没有成功
可能重复:
编写一个返回给定字符串中最长回文的函数
我知道如何在O(n ^ 2)中做到这一点.但似乎存在更好的解决方案.
我发现了这个,并且有一个O(n)答案的链接,但它是用Haskell编写的,对我来说并不清楚.
在c#或类似的答案中获得答案会很棒.