- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚接触 C#,如果这是一个基本问题,请原谅我。我正在使用 .NET 4.0 和 VS 2010 构建 WPF 应用程序。
我有一个类,我在其中存储对象的 List
;这些对象有一个 Point 对象作为字段。其中一种方法返回列表中特定位置的对象:
public Marker markerAtLocation(Point location) {
foreach (Marker nextMarker in Markers)
if (nextMarker.Location().Equals(location))
return nextMarker;
return null;
}
设置断点并使用 Console.WriteLine
我已确认 nextMarker
在返回时有效。但是,在接收器中,对象始终为 null
:
Marker top = markerAtLocation(new Point(location.X, location.Y + 1));
if (top == null)
Console.WriteLine("Top is null");
else
Console.WriteLine("Top is " + top.ToString());
Marker bottom = markerAtLocation(new Point(location.X, location.Y - 1));
if ((bottom != null) && (bottom.player == otherPlayerType()) && (top != null) && (top.player == otherPlayerType()))
return true;
我不知道这里出了什么问题......
请注意,我最初认为这是 .NET 的 Point
结构使用 double 值的问题。我知道在我的应用程序中,位置值始终是整数,所以我没有使用 .NET 点并创建了我自己的点:
class Point {
public int X, Y;
public Point(int X, int Y) {
this.X = X;
this.Y = Y;
}
public bool Equals(Point anotherPoint) {
return ((anotherPoint.X == X) && (anotherPoint.Y == Y));
}
}
如果有任何帮助,我将不胜感激!
编辑:响应 pbirkoff:
class Grid {
public List<Marker> Markers;
public Grid() {
Markers = new List<Marker>();
}
public Grid(List<Marker> markers) {
this.Markers = markers;
}
public void addMarker(Marker newMarker) {
Markers.Add(newMarker);
}
我已经尽我所能尝试了以下解决方案,但都没有帮助。我包含了项目本身的链接以及我试图解决的问题。
项目:http://dl.dropbox.com/u/7828009/ACSLPetteia.zip
问题:http://wcipeg.com/etc/ACSL/VOL%2030/ACSL%20Petteia_sr_3.doc
提前致谢!
最佳答案
我尽可能简洁地实现了你的代码,在适当的地方做了一些模拟(下面的代码),我不能让它失败。我的代码示例中缺少什么:
class Program
{
static void Main(string[] args)
{
LoadMarkers();
var location = new Point(45, 45);
Marker top = markerAtLocation(new Point(location.X, location.Y + 1));
if (top == null)
Console.WriteLine("Top is null");
else
Console.WriteLine("Top is " + top.ToString());
Marker bottom = markerAtLocation(new Point(location.X, location.Y - 1));
}
public static List<Marker> Markers = new List<Marker>();
private static void LoadMarkers()
{
for (var q = 0; q < 50; q++)
for (var w = 0; w < 50; w++)
Markers.Add(new Marker(q, w));
}
public static Marker markerAtLocation(Point location)
{
foreach (Marker nextMarker in Markers)
if (nextMarker.Location().Equals(location))
return nextMarker;
return null;
}
}
class Marker
{
private Point _loc;
public Marker(int x, int y) { _loc = new Point(x, y); }
public Point Location() { return _loc; }
}
class Point
{
public int X, Y;
public Point(int X, int Y)
{
this.X = X;
this.Y = Y;
}
public bool Equals(Point anotherPoint)
{
return ((anotherPoint.X == X) && (anotherPoint.Y == Y));
}
}
关于c# - 在 C# 中,有效的返回值在接收器中变为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7983767/
我正在与 svgpath 合作为了操作 svgs,我需要更改坐标系,使 y 变为 x,x 变为 y。我的问题是有什么办法可以做到这一点。我尝试围绕点 0 0 旋转并按图形的高度进行平移。 最佳答案 作
我有一个来源 Observable那: 注册一些 BroadcastReceivers当它订阅时 取消订阅时取消注册。 我只希望在订阅者数量从 0 增加到 1,或从 1 增加到 0 时发生订阅副作用。
def string_transf(): input('Enter a word or string') #letters = 'abcdefghijklmnopqrstvwxyz'
这个问题在这里已经有了答案: 关闭 12 年前。 Possible Duplicate: Format Number like StackoverFlow (rounded to thousands
我是 R 的初学者,有一个任务,我必须创建一个函数,其中所有数字都重新缩放,Inf 映射到 1,-Inf 映射到 0。我了解如何进行重新缩放,我只是不知道如何添加到函数中,所以 Inf 变为 1,-I
我有一个由二进制值组成的单字节字符数组,我试图将它拆分成一个二维 int 数组(低 nybble 和高 nybble)。这是我的代码: int nybbles[2][4]; //[0][] is lo
有人可以解释为什么 FLEX 4.5 XMLDecoder 对我的 XML 数据这样做吗? var decoder:XMLDecoder = new XMLDecoder; var $object:O
问题: 我在使用 scanf() 时遇到问题。我从阅读论坛之类的地方知道 scanf() 在 C 中有很多问题,但我只是还在学习基础知识,所以我不知道所有的细节。 我想解决的代码片段。 #includ
我遇到了一个问题,其中 UIViewController.navigationController 变为 nil,我正在拼命寻找这个问题的答案。 UINavigationController 在应用程
我在做this教程。 基本上我的问题是,在 front_is_clear 为 false 后,它运行 Jump_over_hurdle,然后停止。 from my_lib import * while
我正在实现一个简单的 Drag'n'Drop Bahevior。首先我要订阅鼠标事件: protected override void OnAttached() { b
这是我的代码的简化版本: template TIterator findMaximalPosition(TIterator begin, TIterator end) { TIterator
大家好,我有这个代码 function computeChange(){ var change; var amountDue = parseFloat(document.getElementById(
就像我的其他问题一样,非常不言自明。问题是,当用户没有选择银行时,变量 bankMoney 在第一次调用 payDay 时会变为 NaN。不选择,它应该通过我的 random 函数进行随机化,但我认为
当我登录时,我已通过身份验证,但当我切换到另一个页面时,req.isAuthenticated 返回 false,并且我位于登录面板上。第二件事是,当我登录时,我不断收到错误“发送后无法设置 head
下面一行 filterM (\x -> Just (x > 0)) [2, 1, 0, -1] 输出 Just [2,1] 和行 filterM (\x -> Just (x > 0)) [] 显示
这可以完美地使用整数进行拓扑排序,但是我想让它与作为参数的字符串类型兼容。有人对如何从这里更改数据结构有任何指导吗?或者我是否必须重写整个内容才能使 [add.edge("a","b");] 工作?我
我正在尝试调试此应用程序,但存在一个大问题。当我尝试将数组保存到数据文件时,一切正常。但是,如果我关闭应用程序并重新打开数组中的 bool 值,则变为 nil。这是保存数组的代码: NSString
程序运行时,有一系列的ListView窗体。我们用项目(作为字符串)填充其中之一,并检查选择状态是否已更改。更改后,我们使用 FocusedItem.Text 获取所选项目的文本。第一次工作得很好,但
我正在编写一个 WP 插件,它连接到另一个 WP 站点,并获取一些数据作为返回(一些强大的条目,带有名称和其他内容)。 一切都很好,我的插件基本上按预期工作 - 但我今天注意到它有一些奇怪的编码问题
我是一名优秀的程序员,十分优秀!