我目前重构我的程序更加面向对象,我遇到了我的对象的构造函数.
所有对象都存储在一个必须是人类可读的数据库中,所以我认为程序员直接传递一个对象的构造函数或者对象将自己获取值是很好的.
所以,我想做的是:
public TestObject(Data.MyDataTable table) {
// Some checks if the table is valid
TestObject(table[0]);
}
public TestObject(Data.MyDataRow row) {
// Some checks if the row is valid
TestObject(row.Name, row.Value);
}
public TestObject(String name, String value) {
// Some checks if the strings are valid
_name = name;
_value = value;
}
Run Code Online (Sandbox Code Playgroud)
所以,正如你所看到的,我想要一种"构造函数链",根据程序员调用它的方式,值将在每一步中传递并验证.我按照我写的方式尝试了它,但它没有用.
Error 'TestObject' is a 'type' but is used like a 'variable'
Run Code Online (Sandbox Code Playgroud)
我也试过写this.TestObject(...)但没有变化.
Error 'TestObject' does not contain a definition for 'TestObject' and
no extension …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,以下代码
ResultSet images = statement.executeQuery("SELECT id, filename, run" +
" FROM images" +
" JOIN comparer_results results ON results.toImageId = images.id" +
" WHERE result <= 100");
while (images.next()) {
statement.executeUpdate("DELETE FROM images WHERE id = "
+ images.getInt("id"));
File imageFile = new File(config.getProperty("system.imageDirectory")
+ File.separator
+ images.getString("filename") + ".jpg");
}
Run Code Online (Sandbox Code Playgroud)
抛出异常
java.sql.SQLException: Operation not allowed after ResultSet closed
Run Code Online (Sandbox Code Playgroud)
在imageFileget实例化的行中.我的理解是这是由images.getString("filename")操作引起的.但为什么ResultSet关闭了?我从来没有调用过这样的方法,对resultset(images.getInt("id"))的第一个操作就可以了.
我想要类似于这里要求的 东西 - 但是,我需要模板依赖于属性的值,这是一个枚举.
这个类看起来很像这样:
class ResultBlock
{
public string Name { get; set; }
public BlockType Type { get; set; }
public IList<ResultBlock> ChildBlocks { get; private set; }
}
Run Code Online (Sandbox Code Playgroud)
哪里BlockType有三个不同的值,BLOCK, FILE, FOLDER- 现在,我想创建一个数据模板,以不同的方式呈现,具体取决于ResultBlock.Type当前对象中的值.
我尝试这样做DataType=,但显然不起作用.我确信只有一些方法可以在XAML中轻松完成.
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type docom:ResultBlock}" ItemsSource="{Binding ChildBlocks}">
<StackPanel Orientation="Horizontal">
<StackPanel.Resources>
<DataTemplate DataType="{x:Type docom:BlockType.BLOCK}">
<TextBlock Text="BLOCK:{Binding Name}" />
</DataTemplate>
</StackPanel.Resources>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.Resources>
Run Code Online (Sandbox Code Playgroud) 我目前正在尝试将可执行控制台应用程序的输出转换为另一个.确切地说,我正在尝试做一些概述:
我有一个我无法编辑的可执行文件,也没有看到它的代码.它在执行时将一些(相当多的是诚实的)行写入控制台.
现在我想编写另一个可执行文件来启动上面的那个并读取它写的东西.
对我来说似乎很简单,所以我开始编码,但结果却出现了一条错误消息 StandardOut has not been redirected or the process hasn't started yet.
我尝试使用这种结构(C#):
Process MyApp = Process.Start(@"C:\some\dirs\foo.exe", "someargs");
MyApp.Start();
StreamReader _Out = MyApp.StandardOutput;
string _Line = "";
while ((_Line = _Out.ReadLine()) != null)
Console.WriteLine("Read: " + _Line);
MyApp.Close();
Run Code Online (Sandbox Code Playgroud)
我可以打开可执行文件,它也可以打开内部的可执行文件,但是一旦读取返回的值,应用程序就会崩溃.
我究竟做错了什么?!
Hoho那里.
我只是试图使用存储过程来增强我的应用程序(.NET 3.5,C#)的性能.
所以我写了一个小测试应用程序,看看它们与普通查询相比有多快,如下所示:
private static long _StartStored;
private static long _EndStored;
private static long _StartNormal;
private static long _EndNormal;
private static TimeSpan _StoredTime;
private static TimeSpan _NormalTime;
private static string[] _Stored = new string[102000];
private static string[] _Normal = new string[102000];
static void Main(string[] args)
{
Console.WriteLine("Querying 2000 normal queries");
_SQLConnection = new SqlConnection(/*my_connection*/);
_SQLConnection.Open();
_StartNormal = DateTime.Now.Ticks;
for (int i = 100000; i <= 102000; i++)
{
DataTable _ResultDataTable = new DataTable();
SqlDataAdapter _SQLAdapter = new SqlDataAdapter(/*my_query*/, _SQLConnection); …Run Code Online (Sandbox Code Playgroud) 我有几张桌子(确切地说,7张)我互相交叉的桌子.这部分给我一些问题;
表"行动"
-----------------------------------------
| ID | Package ID | Action Type | Message |
-----------------------------------------
| 40 | 100340 | 0 | OK |
| 41 | 100340 | 12 | Error |
| 42 | 100340 | 2 | OK |
| 43 | 100341 | 4 | OK |
| 44 | 100341 | 0 | Error |
| 45 | 100341 | 12 | OK |
-----------------------------------------
Run Code Online (Sandbox Code Playgroud)
表"包"
----------------------
| ID | Name |
----------------------
| 100340 …Run Code Online (Sandbox Code Playgroud) 我尝试创建一个进度条,显示解析器读取文本文件的进度.
为此,我使用fileSize = FileInfo(file).Length和在每次迭代中读取文件的字节,我总结了当前行的字节
sum += reader.CurrentEncoding.GetByteCount(currentLine)
我假设当我读完整个文件时,sum应该等于fileSize.
但是,事实并非如此.sum总是低几千字节fileSize.为什么是这样?如何正确创建显示我已解析的文件数量的进度?
我目前正在尝试编写一个RegexReplace来确保输入可以用作有效的XML标记,这意味着:没有空格,没有特殊字符,只有小写等等...
是否有一个共同的方法或我必须从头开始做?
例:
string Invalid = "asd(%4 asKUd n!%mn &§a_As1"; // Invalid as a tag
string Valid = FormatToSafeXmlTag(Invalid); // How to write this function?
// Valid = "asd4_askud_nmna_as1"
Run Code Online (Sandbox Code Playgroud) 我的SQL不是很好,所以我希望有人可以向我解释这个问题(并帮我解决)
我有一张桌子;
++++++++++++++++++++
| ID | Minutes |
++++++++++++++++++++
| 1012 | 15 |
| 1012 | 25 |
| 1015 | 45 |
| 1016 | 10 |
| 1016 | 50 |
++++++++++++++++++++
Run Code Online (Sandbox Code Playgroud)
我希望实现,表格将被转移,因此每个ID都是唯一的,但会将分钟加起来然后看起来像这样:
++++++++++++++++++++
| ID | Minutes |
++++++++++++++++++++
| 1012 | 40 |
| 1015 | 45 |
| 1016 | 60 |
++++++++++++++++++++
Run Code Online (Sandbox Code Playgroud)
该表是原始表的视图,分钟的计算是用"DATEDIFF"完成的 - 这可能有助于...
我有几个修改号码,我需要从中创建文件夹.所以,让我们说{4, 12, 534}.从这里,我需要创建可以相应排序的文件夹;
\004\..
\012\..
\534\..
Run Code Online (Sandbox Code Playgroud)
所以,我需要的是获得最高数字,然后看看每个foldername需要多少填充零,以便在创建它们之后对它们进行正确排序.
如何使用VBA(Excel)执行此操作?我尝试将它们转换为字符串然后处理String操作,但这并没有完全解决.
我希望有人对此有个好主意......
典型的使用方法:
<?php
class A {
public $var;
public function __construct($var){
$this->var = $var;
}
public function do_print(){
print $this->var;
}
}
?>
$obj = new A('Test');
$obj->do_print(); // Test
Run Code Online (Sandbox Code Playgroud)
我该如何实现以下内容:
$obj->var->method();
Run Code Online (Sandbox Code Playgroud)
为什么这有用?
c# ×5
sql ×4
constructor ×1
data-binding ×1
executable ×1
group-by ×1
java ×1
jdbc ×1
join ×1
mysql ×1
numbers ×1
oop ×1
parsing ×1
php ×1
progress-bar ×1
redirect ×1
regex ×1
sql-server ×1
string ×1
text ×1
vba ×1
wpf ×1
xaml ×1
xml ×1