我正在使用C做一个项目,CodeBlocks是我的IDE.Windows Vista是操作系统.我在已经运行的代码中添加了一些新东西,现在可执行文件每次都崩溃了.编译后我没有错误.计算机和编程不是我的领域,但我怀疑它可能与某种内存限制有关(如果存在甚至有意义).我这样说是因为我正在使用三种不同的3D矩阵/维度阵列:
然后,我有另外两个维度1500的1D阵列.这一切都运行良好.
当我添加另外三个尺寸为1500x5的2D矩阵/阵列时,它开始崩溃.如果我评论一些现有的矩阵,新的矩阵工作正常,但一次只能一个.
(顺便说一句,所有上面提到的矩阵都是INT类型,并用指针和callocs定义)
有什么建议?
所以我对C#很新,我一直在学习将我的代码从python转换为C#.现在我偶然发现的问题是:我如何捕获CS7036错误.它在python中被称为"AttributeError",如果你试图实例化一个类而没有所需数量的参数,它就会发生.
public Vector Crossproduct(Vector other)
{
try
{
List<double> output = new List<double>()
{
Y* other.Z - other.Y * Z,0 - (X * other.Z- other.X * Z),X* other.Y - other.X * Y
};
Vector outputvector = new Vector(output);
return outputvector;
}
catch (Exception)
{
throw;
}
}
Run Code Online (Sandbox Code Playgroud)
我用Google搜索了这一点,发现此错误几乎没有任何内容.这是Microsoft的C#文档的链接.这里和这里.
我的问题不是如何修复错误,而是如何捕获它,只是让我很清楚.
注意:由于过去的经验和Profiler软件的建议,我正在优化.我意识到另一种优化方法是GetNeighbors不经常调用,但这是目前的次要问题.
我有一个非常简单的功能如下所述.一般来说,我在foreach循环中调用它.我称这个功能很多(大约每秒100,000次).前段时间,我用Java编写了这个程序的一个变种,并且对我最终用4 if语句替换了几个for循环的速度感到反感.循环展开看起来很难看,但确实在应用程序速度上有明显的差异.所以,我想出了一些潜在的优化,并认为我会就他们的优点和建议征求意见:
使用代码生成实用程序将对GetNeighbors的调用转换为if语句作为编译的一部分.
public static IEnumerable<Square> GetNeighbors(Model m, Square s)
{
int x = s.X;
int y = s.Y;
if (x > 0) yield return m[x - 1, y];
if (y > 0) yield return m[x, y - 1];
if (x < m.Width - 1) yield return m[x + 1, y];
if (y < m.Height - 1) yield return m[x, y + 1];
yield break;
}
//The property of Model used to get elements. …Run Code Online (Sandbox Code Playgroud)MSDN提供了一个数字占位符示例:
1234.5678 ("#####") -> 1235
我发现这个令人困惑(我预期1234或其他),所以我在C#中编写了这个片段来测试它:
Console.WriteLine(String.Format("{0:#}", 1234.5678));
Console.WriteLine(String.Format("{0:#####}", 1234.5678));
Console.WriteLine(String.Format("{0:#}", "1234.5678"));
Console.WriteLine(String.Format("{0:#####}", "1234.5678"));
Run Code Online (Sandbox Code Playgroud)
它给出了这个输出:
1235
1235
1234.5678
1234.5678
Run Code Online (Sandbox Code Playgroud)
请解释.
假设有人决定(是的,这很可怕)以下列方式创建句柄输入:用户在导入你的类后在python控制台上键入命令,该命令实际上是一个类名,类名的__str__函数实际上是一个函数有副作用(例如命令是"north",函数会更改一些全局变量,然后返回描述当前位置的文本).显然这是一个愚蠢的事情,但你会怎么做(如果可能的话)?
请注意,基本问题是如何在__str__不创建类实例的情况下为类定义方法,否则它会很简单(但仍然同样疯狂:
class ff:
def __str__(self):
#do fun side effects
return "fun text string"
ginst = ff()
>>ginst
Run Code Online (Sandbox Code Playgroud) 我有以下代码,它确实有效:
var dataSource = (from p in dv.ToTable().AsEnumerable() where filter(p) select p).AsDataView();
filter是一个Func<DataRow, bool>
dv被一个DataView
dataSource被用作一个DataSource用于DataGrid.
总之,这令我有点难看,我打电话ToTable,AsEnumerable和AsDataView,所以我想知道是否有降低呼叫的数量的方法.
这是我能做到的那么简单吗?
编辑: DataGrid有分页,我使用dataSource来确定条目总数.我并不特别担心这个问题的效率; dv只有几千个项目,表格在内存中维护.
我的activity_main.xml文件如下所示:
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:orientation=”vertical” >
<TextView
android:id=”@+id/mytext”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”@string/hello” />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我应该如何解决此错误?
本地一切正常,但出现“无法检测到代码”错误。
这是这段代码:
private string GetRedirectUriForCurrentConfiguration()
{
#if (DEBUG || DebugDev)
return "http://localhost:1855/";
#endif
return "http://172.16.40.39:1855";
}
Run Code Online (Sandbox Code Playgroud)
我在第四行收到“无法访问”消息 return "http://172.16.40.39:1855";
此语句设置正确吗?