有人知道是否有可能保存或转换DrawingContext为Geometry?
比如之后
using (DrawingContext dc = RenderOpen())
{
dc.DrawLine(penSelected, Data.MidTop, Data.MidTop + vertical);
dc.DrawLine(pen, Data.MidTop - horizontal, Data.MidTop + thickness);
dc.DrawLine(pen, Data.MidTop + vertical - thickness, Data.MidTop + horizontal + vertical);
dc.DrawText(new FormattedText(Data.Time2.ToString("0.0"), cultureinfo, FlowDirection.LeftToRight, typeface, 8, Brushes.Black),
Data.MidTop + 3 * thickness);
dc.DrawText(new FormattedText(Data.Time2.ToString("0.0"), cultureinfo, FlowDirection.LeftToRight, typeface, 8, Brushes.Black),
Data.MidTop + vertical - horizontal - 3 * thickness);
}
Run Code Online (Sandbox Code Playgroud)
以某种方式保存几何中绘制的对象?
您如何看待以下在java中模拟静态类的方法?您可以添加非静态方法,但无法调用它们.
/**
* Utility class: this class contains only static methods and behaves as a static class.
*/
// ... prevent instantiation with abstract keyword
public abstract class Utilities
{
// ... prevent inheritance with private constructor
private Utilities() {}
// ... all your static methods here
public static Person convert(String foo) {...}
}
Run Code Online (Sandbox Code Playgroud) 这很好用:
// Return all objects with code 'code'.
static List<? extends ICode> getObjects(String code, List<? extends ICode> list)
{
<ICode> retValue = new ArrayList<ICode>();
for (ICode item : list)
{
if (item.getCode().equals(code))
{
retValue.add(item);
}
}
return retValue;
}
Run Code Online (Sandbox Code Playgroud)
'单数'版本可以是:
// Return the first object found with code 'code'.
static ICode getObject(String code, List<? extends ICode> lijst)
{
for (ICode item : lijst)
{
if (item.getCode().equals(code)) return item;
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
但ICode我想要返回值而不是返回值<? extends ICode>.可以吗?
看到Jon …
一个类继承自HashSet,以获取一组具有自定义EqualKeys(T x, T y)检查的唯一对象,而不是IEqualityComparer.
public class UniqueSet<T> : HashSet<T> where T : IKey
{
public new void Add(T item)
{
// .. check item for null, empty key etc.
if (base.Any(t => UniqueSet<T>.EqualKeys(t, item)))
{
throw new ArgumentException(..);
}
if (!base.Add(item)) throw new ArgumentException(..);
}
private static bool EqualKeys(T x, T y)
{
return ((IKey)x).Key.Equals(((IKey)y).Key, StringComparison.CurrentCultureIgnoreCase);
}
}
Run Code Online (Sandbox Code Playgroud)
代码无法编译,因为我必须替换base.Any为this.Any.
我恐怕不明白为什么会这样?
在数据库中,我们在要使用联接查询的列上创建索引。
Linq to objects是否以任何方式促进了这一点?
我认为,如果内存中的二叉树(索引)以某种方式可以将List映射到T的特定属性,则可以(大大)提高搜索性能。
我在考虑不必针对插入或删除进行优化的列表。
可以关闭索引以进行另一种优化。
是否可以声明一个名称空间:
<Window xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MyApp.MainWindow"/>
Run Code Online (Sandbox Code Playgroud)
在后面的代码中,例如在构造函数中.
public MainWindow()
{
// ... here
}
Run Code Online (Sandbox Code Playgroud)
目的:减少冗长; 在一个地方声明名称空间并使用继承.
编辑:我尝试添加
[assembly: XmlnsDefinition("http://mycompany/myapp", "clr-namespace:MyApp.Controls")]
[assembly: XmlnsPrefix("http://mycompany/myapp", "myc")]
Run Code Online (Sandbox Code Playgroud)
到AssemblyInfo.cs
但构建与错误"的命名空间前缀'MYC结束’没有定义".
所以我在与xaml文件所在的项目相同的项目中使用attirbutes.
我希望我可以使用这种模式:
var task = Task.Run(() => Agent.GetUserType(Instance));
await task;
string information = task.GetExceptionOrStatus(); // extension method
Run Code Online (Sandbox Code Playgroud)
当我的sql服务器没有启动时 - 就像一个测试用例 - 我看到WCF服务抛出的异常没有被任务正常处理,我得到:
Microsoft中出现了类型'System.ServiceModel.FaultException'的异常. Threading.Tasks.dll但未在用户代码中处理.
我的印象是我的代码能够从任务对象中提取错误.
我该怎么做得更好?
我正在处理一个商业Java API,它只公开以下日志记录配置:
cplex.setOut(OutputStream arg0);
Run Code Online (Sandbox Code Playgroud)
我想记录两个流:文件和控制台.可能吗?
在C#3.0中,框架与3.0(程序集mscorlib.dll,v2.0.50727)
System.IO.StreamWriter具有以下构造函数:
public StreamWriter(Stream stream, Encoding encoding);
public StreamWriter(string path, bool append, Encoding encoding);
Run Code Online (Sandbox Code Playgroud)
所以代码
Encoding enc = System.Text.Encoding.GetEncoding("iso-8859-1");
writer = new StreamWriter(filename, enc);
writer = new StreamWriter(filename, false, enc);
Run Code Online (Sandbox Code Playgroud)
给出了编译错误"最好的重载方法匹配...有一些无效的参数"......"无法在第二行从'System.Text.Encoding'转换为'bool'".
对不起,不是问题,而是错误.
在C#类中,我有一个列表和列表的两个不同的getter:
private List<A> a;
public List<A> EveryA
{
get
{
if (a == null) a = new List<A>();
return a;
}
}
public List<A> FilteredA
{
get
{
return EveryA.FindAll(a => a.IsInFilter);
}
}
Run Code Online (Sandbox Code Playgroud)
现在我的问题是:语法怎么样FilteredA.Add(this);?
它编译并运行但不能将任何项添加到任何列表中.
一个更好的编译器是否必须通知(小)问题?
c# ×5
java ×3
wpf ×2
async-await ×1
constructor ×1
exception ×1
generics ×1
getter ×1
hashset ×1
indexing ×1
list ×1
outputstream ×1
return-value ×1
streamwriter ×1
xaml ×1