要搭建测试环境。
Webbrowser使用方面:
重新加载一页面后,要获取新的内容要使用重新使用browser.Document获取;

HtmlElement的GetElementsByTagName(html标记)是HtmlElement中包括的所有标记的集合,如果相同元素有嵌套时要注意。如:
<table>
<tr>
     <td>1</td>
</tr>
<tr>
<td>
        <table>
         <tr>
         <td>2</td>
         </tr><tr>
         <td>3</td>
        </tr>
       </table>
</td>
</tr>
</table>

如果获取最外层table节点为HtmlElement  he,此时使用he.GetElementsByTagName(“tr”),则包含4个元素:

0:
<tr>
<td>1</td>
</tr>
1:
<tr>
<td>
<table>
<tr>
<td>2</td>
</tr><tr>
<td>3</td>
</tr>
</table>
</td>
</tr>
2:
<tr>
<td>2</td>
</tr>
3:
<tr>
<td>3</td>
</tr>

如果要获取class属性,要使用HtmlElement he;he.getAttribute(“className”); 或he.getAttribute(“classname”); 即不区分大小写

下拉列表设置属性:
he.SetAttribute("value", "2013-1-1");  
he.RaiseEvent("onChange");    //触发onChange事件,如果在后续代码中使用he.invokeScript(js名称);这个可以不用写           

其它:

Dictionary使用中如果使用foreach travel时不能进行更改(增加、删除、修改),否则会报错:
Collection was modified; enumeration operation may not execute.
遍历并修改:

#region Dictionary Travel modify
public static void mainTest()
{
    Dictionary<String, Int32> dic = new Dictionary<String, Int32>();
    dic.Add("1", 1);
    dic.Add("2", 2);
    dic.Add("3", 3);
    foreachTravelDic(dic);
    modifyDic1(dic);
    foreachTravelDic(dic);
    modifyDic2(dic);
    foreachTravelDic(dic);
    Console.ReadKey();
}

public static void foreachTravelDic(Dictionary<String, Int32> dic)
{
    foreach (KeyValuePair<String, Int32> kvp in dic)
    {
        Console.WriteLine(String.Format("Key:{0}; Value:{1}", kvp.Key, kvp.Value));
        //dic[kvp.Key] = 2;//此操作会报错
    }
}

 

private static void modifyDic2(Dictionary<String, Int32> dic)
{
    String[] keyStr = dic.Keys.ToArray<String>();
    for (int i = 0; i < keyStr.Length; i++)
    {
        dic[keyStr[i]] = dic[keyStr[i]] + 22;
    }

}

private static void modifyDic1(Dictionary<String, Int32> dic)
{
    int dicCount = dic.Keys.Count;
    String[] strKey = new String[dicCount];
    dic.Keys.CopyTo(strKey, 0);//支持.net2.0
    for (int i = 0; i < strKey.Length; i++)
    {
        if (dic.ContainsKey(strKey[i]))
        {
            dic[strKey[i]] = dic[strKey[i]] + 11;
        }
    }
}
#endregion
output:

补充:
foreach在travel Dictionary时报错的原因:
http://www.cnblogs.com/dudu/archive/2006/07/31/464391.html
在执行foreach时,其他线程对_dictionary进行了Add操作,改变了_dictionary中的数据,从而产生了上述的异常信息。

     那为什么会产生这样的异常信息呢?
     foreach实际上执行的代码是:   

Dictionary<int, int>.Enumerator enumerator = _dictionary.GetEnumerator(); 
try

while (enumerator.MoveNext())  
   { 
    } 

finally

   IDisposable d = enumerator as IDisposable; 
if (d != null) d.Dispose(); 
}

     通过Reflector查看Dictionary<TKey, TValue>.Enumerator.MoveNext()源代码,我们会发现开始处有这样的代码:

if (this.version != this.dictionary.version)
      {
            ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
      }

     而异常就是在这里发生的,因为Add操作时改变了Dictionary的version,通过查看Insert(TKey key, TValue value, bool add)的源代码会看出。
     我觉得Dictionary<TKey, TValue>应该提供一个方法,可以设置在MoveNext时是否进行版本检查,因为有时在foreach操作时,可能并不关心Dictionary中的数据是否被修改,我遇到的就是这样的情况,现在由于这个问题而不能使用foreach,而只能采取其他方法遍历Dictionary<TKey, TValue>中的数据。

Dictionary类型在作为参数传递时:
public static void Main(String[] args) {
           #region test Dic
            IDictionary<String,String> sumDic=new Dictionary<String,String>();
            IDictionary<String, String> secDic = new Dictionary<String, String>();
            sumDic.Add("ak","av");
            sumDic.Add("bk", "bv");
            sumDic.Add("ck", "cv");
            sumDic.Add("dk", "dv");
            sumDic.Add("ek", "ev");

            secDic = testDic(sumDic);//引用传递
            foreach (KeyValuePair<String, String> kvp in sumDic)
            {
                Console.WriteLine(String.Format("{0}====>{1}",kvp.Key,kvp.Value));
            }
            Console.WriteLine("----------------------------");
            foreach (KeyValuePair<String, String> kvp in secDic)
            {
                Console.WriteLine(String.Format("{0}====>{1}", kvp.Key, kvp.Value));
            }
//            output:
//            ak====>av
//            bk====>bv
//            ck====>cv
//            ek====>ev
//----------------------------
//            dk====>dv

            #endregion
            Console.ReadKey();

        }

private static IDictionary<String, String> testDic(IDictionary<String, String> sumDic)
  {
      IDictionary<String, String> secDic = new Dictionary<String, String>();
      String[] keysStr=sumDic.Keys.ToArray<String>();

      for (int i = 0; i < keysStr.Length; i++)
      {
          if (sumDic[keysStr[i]].Equals("dv"))
          {
              secDic.Add(keysStr[i], sumDic[keysStr[i]]);
              sumDic.Remove(keysStr[i]);
          }
      }

      return secDic;
  }

出现的问题:
1、因业务需要更改了几个关键方法,程序没有报异常,但是有一个方法一直没有执行,一直很困惑
由于开发环境和生产环境分离,也无法在现网调试,只能分析代码,最后发现问题就在改的方法上,中间的过渡方法执行了另一个操作,但是没有将值返回,导致向上层传递了空Dictionary,虽然没有报错,但不满足另一个方法的执行条件。。。。

 

2、日志输出时忽略了一些关键信息,需先规划好要输入哪些必要信息;

3、IDictionary<String, int[]>  数组作为dic的value时出现的问题:

数组是引用类型,如果在第二次使用时没有实始化就重新使用,会影响到以前的值:
有问题的:

       public static void TestDicArray() {
Dictionary<String, int[]> dic = new Dictionary<String, int[]>(); int[] valueArray=new int[2];
valueArray[0] = 1;
valueArray[1] = 1; dic.Add("test1",valueArray);
//valueArray = new int[2];
valueArray[0] = 2;
valueArray[1] = 2; dic.Add("test2", valueArray); //valueArray = new int[2];
valueArray[0] = 3;
valueArray[1] = 3; dic.Add("test3", valueArray); // valueArray = new int[2];
valueArray[0] = 4;
valueArray[1] = 4; dic.Add("test4", valueArray); // valueArray = new int[2];
valueArray[0] = 5;
valueArray[1] = 5; dic.Add("test5", valueArray); foreach (KeyValuePair<String,int[]> kvp in dic)
{ Console.WriteLine(kvp.Key);
int[] tempInt = kvp.Value;
Console.WriteLine(tempInt[0]+"\t"+tempInt[1]); Console.WriteLine(dic[kvp.Key][0]+"\t"+dic[kvp.Key][1]); } }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

正确的:

       public static void TestDicArray() {
            Dictionary<String, int[]> dic = new Dictionary<String, int[]>();
 
          int[] valueArray=new int[2];
          valueArray[0] = 1;
          valueArray[1] = 1;
 
          dic.Add("test1",valueArray);
          valueArray = new int[2];
          valueArray[0] = 2;
          valueArray[1] = 2;
 
          dic.Add("test2", valueArray);
 
          valueArray = new int[2];
          valueArray[0] = 3;
          valueArray[1] = 3;
 
          dic.Add("test3", valueArray);
 
          valueArray = new int[2];
          valueArray[0] = 4;
          valueArray[1] = 4;
 
          dic.Add("test4", valueArray);
 
          valueArray = new int[2];
          valueArray[0] = 5;
          valueArray[1] = 5;
 
          dic.Add("test5", valueArray);
 
 
 
          foreach (KeyValuePair<String,int[]> kvp in dic)
          {
 
              Console.WriteLine(kvp.Key);
              int[] tempInt = kvp.Value;
              Console.WriteLine(tempInt[0]+"\t"+tempInt[1]);
 
              Console.WriteLine(dic[kvp.Key][0]+"\t"+dic[kvp.Key][1]);
 
          }
        
        
        }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

OutPut:

                    //input value attribute;InnerText is null
HtmlElementCollection hecSelects = hd.GetElementsByTagName("input");
foreach (HtmlElement heSelect in hecSelects)
{
showMsgInText("value:"+heSelect.GetAttribute("value"));
showMsgInText("InnerText:" + heSelect.InnerText);
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

C#开发一应用的总结的更多相关文章

  1. 避免重复造轮子的UI自动化测试框架开发

    一懒起来就好久没更新文章了,其实懒也还是因为忙,今年上半年的加班赶上了去年一年的加班,加班不息啊,好了吐槽完就写写一直打算继续的自动化开发 目前各种UI测试框架层出不穷,但是万变不离其宗,驱动PC浏览 ...

  2. App开发:模拟服务器数据接口 - MockApi

    为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...

  3. 使用HTML5开发Kinect体感游戏

    一.简介 我们要做的是怎样一款游戏? 在前不久成都TGC2016展会上,我们开发了一款<火影忍者手游>的体感游戏,主要模拟手游章节<九尾袭来 >,用户化身四代,与九尾进行对决, ...

  4. Android SwipeRefreshLayout 下拉刷新——Hi_博客 Android App 开发笔记

    以前写下拉刷新 感觉好费劲,要判断ListView是否滚到顶部,还要加载头布局,还要控制 头布局的状态,等等一大堆.感觉麻烦死了.今天学习了SwipeRefreshLayout 的用法,来分享一下,有 ...

  5. Android Studio配置 AndroidAnnotations——Hi_博客 Android App 开发笔记

    以前用Eclicps 用习惯了现在 想学学 用Android Studio 两天的钻研终于 在我电脑上装了一个Android Studio 并完成了AndroidAnnotations 的配置. An ...

  6. Android请求网络共通类——Hi_博客 Android App 开发笔记

    今天 ,来分享一下 ,一个博客App的开发过程,以前也没开发过这种类型App 的经验,求大神们轻点喷. 首先我们要创建一个Andriod 项目 因为要从网络请求数据所以我们先来一个请求网络的共通类. ...

  7. Angular2入门系列教程1-使用Angular-cli搭建Angular2开发环境

    一直在学Angular2,百忙之中抽点时间来写个简单的教程. 2016年是前端飞速发展的一年,前端越来越形成了(web component)组件化的编程模式:以前Jquery通吃一切的田园时代一去不复 ...

  8. 构建一个基本的前端自动化开发环境 —— 基于 Gulp 的前端集成解决方案(四)

    通过前面几节的准备工作,对于 npm / node / gulp 应该已经有了基本的认识,本节主要介绍如何构建一个基本的前端自动化开发环境. 下面将逐步构建一个可以自动编译 sass 文件.压缩 ja ...

  9. 读书笔记:《HTML5开发手册》--HTML5新的结构元素

    读书笔记:<HTML5开发手册> (HTML5 Developer's CookBook) 虽然从事前端开发已有很长一段时间,对HTML5标签也有使用,但在语义化上面理解还不够清晰.之前在 ...

  10. 总结:Mac前端开发环境的搭建(配置)

    新年新气象,在2016年的第一天,我入手了人生中第一台自己的电脑(大一时好友赠送的电脑在一次无意中烧坏了主板,此后便不断借用别人的或者网站的).macbook air,身上已无分文...接下来半年的房 ...

随机推荐

  1. ionic xcode8 App上传应用详细流程

    第一步: 进入开发者官网 https://developer.apple.com   2.证书 序号1:开发者证书,用于真机调试   序号2:上传证书,用于发布最终版 3.证书申请 由于我现在是要发布 ...

  2. Javascript设计模式理论与实战:享元模式

    享元模式不同于一般的设计模式,它主要用来优化程序的性能,它最适合解决大量类似的对象而产生的性能问题.享元模式通过分析应用程序的对象,将其解析为内在数据和外在数据,减少对象的数量,从而提高应用程序的性能 ...

  3. .net core signalR 忽略https 证书

    var connection = new HubConnectionBuilder().WithUrl(serverUrl, option => { option.HttpMessageHand ...

  4. C#Winfrom Listview数据导入Excel

    需引用 public void ExportToExecl() { System.Windows.Forms.SaveFileDialog sfd = new SaveFileDialog(); sf ...

  5. 《JavaScript高级程序设计》3.7 函数

    位于return语句之后的代码不会执行; return语句也可以不带有任何返回值. 这种情况下, 函数在停止执行后会返回undefined值. 这种用法一般用在需要提前停止函数执行而又不需要返回值的情 ...

  6. Day 9 作业题(完成)

    # 练习题# 1.整理函数相关知识点,画思维导图,写博客 # 2.写函数,检查获取传入列表或元组对象的所有奇数位索引对应的元素,并将其作为新列表返回给调用者.'''def func1(argv): f ...

  7. 902. Numbers At Most N Given Digit Set

    We have a sorted set of digits D, a non-empty subset of {'1','2','3','4','5','6','7','8','9'}.  (Not ...

  8. Union Find-547. Friend Circles

    There are N students in a class. Some of them are friends, while some are not. Their friendship is t ...

  9. elasticsearch geo_point 地理位置过滤 按经度排序

    elasticsearch 支持强大的经纬度坐标过滤. 1.首先要建立坐标类型的字段'type' ='geo_point' es存储的值是这样的: "poi": [        ...

  10. Flask从入门到精通之重定向和用户会话

    最新版的hello.py 存在一个可用性问题.用户输入名字后提交表单,然后点击浏览器的刷新按钮,会看到一个莫名其妙的警告,要求在再次提交表单之前进行确认.之所以出现这种情况,是因为刷新页面时浏览器会重 ...