日期:2014-05-18  浏览次数:20775 次

浏览器参数判断问题
通过shell命令运行C#写的浏览器并打开指定网页,现在在判断传递的参数是否为空,出错了,请帮忙看看原因,谢谢。 
代码如下

Program.cs的
namespace WindowsFormsApplication1
{
  static class Program
  {
  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main(string[] args)
  {
  Application.EnableVisualStyles();
  Application.SetCompatibleTextRenderingDefault(false);
  if (args.Length!=0)
  Application.Run(new Form1(args[0]));
  else
  Application.Run(new Form1());
  }
  }
}


Form1.cs 的

namespace WindowsFormsApplication1
{
  public partial class Form1 : Form
  {
  public string url;
  public Form1(string cmd)
  {
  url=cmd;
  InitializeComponent();
  }
  public Form1()
  {
  InitializeComponent();
  }
  private void Form1_Load(object sender, EventArgs e)
  {
  if (url.Length != 0)//未将对象引用设置到对象的实例
  webBrowser1.Navigate(url);
  }
  }
}

------解决方案--------------------
if (url!=null&&url.Length != 0)