[英]c# Error Message - Type Or namespace definition or end of file expected
全部,我在編寫ac#腳本,我想檢查標題為“腳本錯誤”的Windows彈出窗口是否可見並返回True或False。 為此,我不得不使用static extern ,我相信我使用的不正確,但不確定如何糾正。
請有人建議如何解決我看到的錯誤:
錯誤消息-類型或名稱空間定義或預期的文件結尾
**請注意引起問題的括號,我已將其標記為錯誤偏誤,但是我不確定是導致整體問題的原因。
請在下面查看完整的代碼:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
namespace Dynamic.Script_8D737880D773F26
{ **Error Parathesis
// Script generated by Pega Robotics Studio 8.0.2032.0
// Please use caution when modifying class name, namespace or attributes
[OpenSpan.TypeManagement.DynamicTypeAttribute()]
[OpenSpan.Design.ComponentIdentityAttribute("Script-8D737880D773F26")]
public sealed class Script
{
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr zeroOnly, string lpWindowName);
}
{
public bool ScriptErrorVisible()
{
if (FindWindowByCaption(IntPtr.Zero, "Script Error") != IntPtr.Zero)
{
return true;
}
else
{
return false;
}
}
}
} **Error Parenthesis
看來您有幾個懸掛的支架。 嘗試這個。
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
namespace Dynamic.Script_8D737880D773F26
{
// Script generated by Pega Robotics Studio 8.0.2032.0
// Please use caution when modifying class name, namespace or attributes
[OpenSpan.TypeManagement.DynamicTypeAttribute()]
[OpenSpan.Design.ComponentIdentityAttribute("Script-8D737880D773F26")]
public sealed class Script
{
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr zeroOnly, string lpWindowName);
public bool ScriptErrorVisible()
{
if (FindWindowByCaption(IntPtr.Zero, "Script Error") != IntPtr.Zero)
{
return true;
}
else
{
return false;
}
}
}
}
正如其他人所說的,一個好的開始是適當縮進。 要實際解釋您的問題,而不只是發布答案,請參見以下解釋:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
namespace Dynamic.Script_8D737880D773F26
{
// Script generated by Pega Robotics Studio 8.0.2032.0
// Please use caution when modifying class name, namespace or attributes
[OpenSpan.TypeManagement.DynamicTypeAttribute()]
[OpenSpan.Design.ComponentIdentityAttribute("Script-8D737880D773F26")]
public sealed class Script
{
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr zeroOnly, string lpWindowName);
} // << Your class ends here
{ // << Opened brackets without declaring a class
public bool ScriptErrorVisible()
{
if (FindWindowByCaption(IntPtr.Zero, "Script Error") != IntPtr.Zero)
{
return true;
}
else
{
return false;
}
}
} // << This would close the class, but you haven't declared one
} // << This ends the namespace
因此,這就是答案:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
namespace Dynamic.Script_8D737880D773F26
{
// Script generated by Pega Robotics Studio 8.0.2032.0
// Please use caution when modifying class name, namespace or attributes
[OpenSpan.TypeManagement.DynamicTypeAttribute()]
[OpenSpan.Design.ComponentIdentityAttribute("Script-8D737880D773F26")]
public sealed class Script
{
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindowByCaption(IntPtr zeroOnly, string lpWindowName);
public bool ScriptErrorVisible()
{
if (FindWindowByCaption(IntPtr.Zero, "Script Error") != IntPtr.Zero)
{
return true;
}
else
{
return false;
}
} // << Closes the ScriptErrorVisible method
} // << Closes the Script class
} // << Closes the Dynamic.Script_8D737880D773F26 namespace
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.