Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi到C#的转换_C#_Delphi - Fatal编程技术网

Delphi到C#的转换

Delphi到C#的转换,c#,delphi,C#,Delphi,我需要将一个Delphi程序转换为C#,我对“with”有问题 我想不出正确的转换方法。任何帮助都会很好。 我已经附上了我遇到问题的代码片段。 QueryLchistory是sql查询,我还删除了while循环中执行的语句 with QueryLcHistory do begin First; RemainingMargin := 0; while (not Eof) and Another test Case do begin //Stateme

我需要将一个Delphi程序转换为C#,我对“with”有问题 我想不出正确的转换方法。任何帮助都会很好。 我已经附上了我遇到问题的代码片段。 QueryLchistory是sql查询,我还删除了while循环中执行的语句

with QueryLcHistory do begin
First;
 RemainingMargin := 0;

     while (not Eof) and Another test Case
         do begin
        //Statements #1
        Next;
     end;

    while (not Eof ) and Another test Case2
      do begin
     // Statements #2
       Next;
    end; 
end; {with}

with
所做的唯一事情就是在其作用域的命名空间中提升其操作数。
这意味着编译器会将
QueryLcHistory.
前缀添加到该前缀有效的每个标识符。
这种特殊处理只在with语句的begin end块中进行,之后一切照旧

因为C#没有
with
语句,所以您必须首先在Delphi中创建工作代码,而不使用
with
语句,这可以转换为C#代码

要使用删除
,请执行以下步骤

  • 删除,保留开始
    {with QueryLcHistory do}开始

  • 用with语句中的内容作为每个标识符的前缀

    QueryLcHistory.First
    QueryLcHistory.RemainingMargin:=0//etc

  • 编撰

  • 从编译器给出错误的所有标识符中删除
    QueryLcHistory

  • 确保新代码的行为方式与旧代码相同

  • 现在,您已经获得了易于翻译为C的简单代码

    与邪恶为伍
    您如何知道哪些语句受带的
    影响,哪些不受影响?
    除非你已经记住了QueryLcHistory(或其他任何版本)的完整界面,否则你就不知道了。

    如果没有带
    ,范围是明确的,并且在您的脸上。使用
    时,它是隐式的和隐蔽的。永远不要将
    用于
    ,因为很难分辨哪些语句在with语句的范围内,哪些语句与其他语句相关

    with
    的唯一作用是在其作用域的命名空间中提升其操作数。
    这意味着编译器会将
    QueryLcHistory.
    前缀添加到该前缀有效的每个标识符。
    这种特殊处理只在with语句的begin end块中进行,之后一切照旧

    因为C#没有
    with
    语句,所以您必须首先在Delphi中创建工作代码,而不使用
    with
    语句,这可以转换为C#代码

    要使用
    删除
    ,请执行以下步骤

  • 删除,保留开始
    {with QueryLcHistory do}开始

  • 用with语句中的内容作为每个标识符的前缀

    QueryLcHistory.First
    QueryLcHistory.RemainingMargin:=0//etc

  • 编撰

  • 从编译器给出错误的所有标识符中删除
    QueryLcHistory

  • 确保新代码的行为方式与旧代码相同

  • 现在,您已经获得了易于翻译为C的简单代码

    与邪恶为伍
    您如何知道哪些语句受带的
    影响,哪些不受影响?
    除非你已经记住了QueryLcHistory(或其他任何版本)的完整界面,否则你就不知道了。
    如果没有带
    ,范围是明确的,并且在您的脸上。使用
    时,它是隐式的和隐蔽的。永远不要将
    用于
    ,因为很难分辨哪些语句在with语句的范围内,哪些语句与其他语句相关

    在C#中没有类似于with语句的东西,而在VB中有

    可以指定如下对象的属性:

    StringBuilder sb = new StringBuilder()
      .Append("foo")
      .Append("bar")
      .Append("zap");
    
    但是,您不能在obejct之后放置一段时间,无论如何,您可以创建自己的QueryLcHistory方法,或者您可以简单地在任何适用于它的方法之前重复QueryLcHistory:

    将QueryLcHistory假设为数据表:

    int RemainingMargin = 0;
    DataRow row;
    
      IEnumerator e = QueryLcHistory.rows.GetEnumerator();
    
      while (e.MoveNext() && Another test Case) {
           row = e.Current
           // Statements #1
       }
    
      while (e.MoveNext() && Another test Case 2) {
           row = e.Current
           // Statements #2
       }
    
    在C#中没有类似于with语句的东西,而在VB中有

    可以指定如下对象的属性:

    StringBuilder sb = new StringBuilder()
      .Append("foo")
      .Append("bar")
      .Append("zap");
    
    但是,您不能在obejct之后放置一段时间,无论如何,您可以创建自己的QueryLcHistory方法,或者您可以简单地在任何适用于它的方法之前重复QueryLcHistory:

    将QueryLcHistory假设为数据表:

    int RemainingMargin = 0;
    DataRow row;
    
      IEnumerator e = QueryLcHistory.rows.GetEnumerator();
    
      while (e.MoveNext() && Another test Case) {
           row = e.Current
           // Statements #1
       }
    
      while (e.MoveNext() && Another test Case 2) {
           row = e.Current
           // Statements #2
       }
    

    这不是一个循环。没有一个c#等同于with。如果你不明白这意味着什么,请阅读文档。请在这里询问之前这样做。With不是循环。没有一个c#等同于with。如果你不明白这意味着什么,请阅读文档。在这里问之前请先问一下。