【发布时间】:2016-08-01 12:17:22
【问题描述】:
我在VB中有这段代码
Private Function ReadProfileViewPlotOptions(ByVal SavePath As String) As ProfileViewOptionsType
Dim FileName As String
Dim filenumber As Short
Dim InInt As Integer
FileName = System.IO.Path.Combine(SavePath, "cfgpropt.sys")
If Not System.IO.File.Exists(FileName) Then
With ReadProfileViewPlotOptions
.ViewConcave = CBool(GetSetting(My.Application.Info.Title, "ProfileViewPlotOptions", "ViewConcave", CStr(1)))
-----
我把它转成C#这样
private static Mold_Power_Suite.Model.FrontEndStructures.PlanViewOptionsType ReadPlanViewPlotOptions(string SavePath)
{
var title = ((AssemblyTitleAttribute)System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0]).Title;
Mold_Power_Suite.Model.FrontEndStructures.PlanViewOptionsType functionReturnValue = default(Mold_Power_Suite.Model.FrontEndStructures.PlanViewOptionsType);
string FileName = null;
short filenumber = 0;
int InInt = 0;
FileName = System.IO.Path.Combine(SavePath, "cfgplopt.sys");
if (!System.IO.File.Exists(FileName))
{
functionReturnValue.ViewConcave = Convert.ToBoolean(Interaction.GetSetting(title, "PlanViewPlotOptions", "ViewConcave", Convert.ToString(1)));
-----
}
在运行时,我的代码正在中断
functionReturnValue.ViewConcave = Convert.ToBoolean(Interaction.GetSetting(title, "PlanViewPlotOptions", "ViewConcave", Convert.ToString(1)));
编译器显示的错误是“Format Exception Unhandled”。String 未被识别为有效的布尔值。”
我哪里错了?
【问题讨论】:
-
GetSetting 返回的值是多少?
-
尝试将内部的“Convert.ToString”切换为“Convert.ToBoolean”
-
@Kevin MSDN 这么说msdn.microsoft.com/en-us/library/…