我想在主程序里面引用 links这里该怎么写是WebPage.links对吗?可是为什么提示非静态方法或属性要求被引用,是下面的类写的不用吗?
using System;
using System.Data;
using System.Configuration;
using System.Net;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web;namespace Web
{
public class WebPage
{
public IList<string> m_links; public IList<string> Links
{
get
{
if (m_links.Count == 0) getLinks();
return m_links;
}
}
public IList<string> getLinks()
{
m_links = new List<string>();
string result = @"<dd><a href=""http://www.baidu.com"" title=百度 target=_blank>百度</a></dd><dd><a href=""http://www.sohu.com"" title=搜狐 target=_blank>搜狐</a></dd>";
if (m_links.Count == 0)
{
Regex[] regex = new Regex[2];
regex[0] = new Regex(@"<a\shref\s*=""(?<URL>[^""]*).*?>(?<title>[^<]*)</a>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
regex[1] = new Regex("<[i]*frame[^><]+src=(\"|')?(?<url>([^>\"'\\s)])+)(\"|')?[^>]*>", RegexOptions.IgnoreCase); for (int i = 0; i < 2; i++)
{
Match match = regex[i].Match(result);
while (match.Success)
{
try
{
string url = HttpUtility.UrlDecode(new Uri(match.Groups["URL"].Value).AbsoluteUri);
m_links.Add(url);
}
catch (Exception ex) { Console.WriteLine(ex.Message); };
match = match.NextMatch();
}
}
}
return m_links;
}
}
}
using System;
using System.Data;
using System.Configuration;
using System.Net;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web;namespace Web
{
public class WebPage
{
public IList<string> m_links; public IList<string> Links
{
get
{
if (m_links.Count == 0) getLinks();
return m_links;
}
}
public IList<string> getLinks()
{
m_links = new List<string>();
string result = @"<dd><a href=""http://www.baidu.com"" title=百度 target=_blank>百度</a></dd><dd><a href=""http://www.sohu.com"" title=搜狐 target=_blank>搜狐</a></dd>";
if (m_links.Count == 0)
{
Regex[] regex = new Regex[2];
regex[0] = new Regex(@"<a\shref\s*=""(?<URL>[^""]*).*?>(?<title>[^<]*)</a>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
regex[1] = new Regex("<[i]*frame[^><]+src=(\"|')?(?<url>([^>\"'\\s)])+)(\"|')?[^>]*>", RegexOptions.IgnoreCase); for (int i = 0; i < 2; i++)
{
Match match = regex[i].Match(result);
while (match.Success)
{
try
{
string url = HttpUtility.UrlDecode(new Uri(match.Groups["URL"].Value).AbsoluteUri);
m_links.Add(url);
}
catch (Exception ex) { Console.WriteLine(ex.Message); };
match = match.NextMatch();
}
}
}
return m_links;
}
}
}
解决方案 »
- WPF ShowDialog的坑爹问题
- C#中事务的应用问题
- 散分
- 在IE下通过web com 方式调用....
- 有懂WAP的吗?请帮下忙,急啊~~~~~~
- 太奇怪,急:存储过程在查询分析器中可无限次执行,但在SqlComand中只能正确执行一次,第二次就报错?我需要在SqlComand中多次执行。请给
- 问一个比较菜的问题?
- c# 异步 回调读取。让回调函数执行完后返回
- TreeNode控件有折叠下一级节点这个命令吗?
- VS.NET英文正式版安装出错,帮忙看看?
- C# HttpListener 端口被占用的问题 求教
- C# 结取文件,怎么获取指定的.jpg.bmp文件,并且可以有短文件名及完整文件名?
this是类的隐藏实例。
WebPage mypage = new WebPage();
调用mypage.links
我是这样调用的,IList<string> ttt = WebPage.Links;
请问您输出的代码是否是下面格式的?
List<string> ttt = new List<string>();
ttt.Add("http://www.baidu.com");
ttt.Add("http://www.sohu.com");
我是这样调用的,IList<string> ttt = WebPage.Links;
请问您输出的代码是否是下面格式的?
List<string> ttt = new List<string>();
ttt.Add("http://www.baidu.com");
ttt.Add("http://www.sohu.com");