博文

StringCollection FAQ [C#, BCL](2007-11-12 11:38:00)

摘要:转自http://www.cnblogs.com/allenlooplee/archive/2005/03/19/121686.html Q:如何使用StringCollection[1]? A:通常我们有三种方法来访问StringCollection里面的string元素: // Code #01

StringCollection sc = new StringCollection();
sc.AddRange(textBox1.Lines);

// StringCollection used together with StringEnumerator.
StringEnumerator se = sc.GetEnumerator();
while (se.MoveNext())
{
    Console.WriteLine(se.Current);
}

// 'foreach' syntax used.
foreach(string str in sc)
{
    Console.WriteLine(str);
}

// 'for' syntax used.
for(int i = 0; i < sc.Count; i++)
{
    Console.WriteLine(sc[i]);
} Q:与ArrayList相比,StringCollection有什么优势? A:首先让我们来看看如下代码: // Code #02

// StringCollection used for Stri......

阅读全文(2846) | 评论:0

单件模式例子(2007-11-10 12:44:00)

摘要:转自http://terrylee.cnblogs.com/archive/2005/12/09/293509.html using System;
using System.Collections.Generic;
using System.Text;
using System.Threading; namespace SingletonCounter
{
    ///<summary>
    ///功能:简单计数器的单件模式
    ///编写:XXX
    ///日期:2007年11月10日
    ///</summary>     public class CounterSingleton
    {
        ///存储唯一的实例
        static CounterSingleton uniCounter = new CounterSingleton();         ///存储计数值
        private int totNum = 0;         private CounterSingleton()
        {
            ///线程延迟2000毫秒
       &n......

阅读全文(2245) | 评论:0

label(c#winform)链接(2007-11-03 20:42:00)

摘要:  private void label1_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("IEXPLORE.EXE", "http://www.baidu.com");
        }......

阅读全文(2108) | 评论:1

调用可扩展对象 xml(2007-11-03 17:10:00)

摘要:xml文件: <?xml version="1.0" encoding="utf-8" ?>
<circles>
  <circle>
    <radius>15</radius>
  </circle>
  <circle>
    <radius>18</radius>
  </circle>
</circles> xslt 文件 <?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:myns="urn:myobject">
  <xsl:template match="circles/circle">
    <xsl:copy>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="radius">
    <circumference>
      <xsl:value-of select="myns:getcircumference(.)"/>
    </circumference>
  </xsl:template>
</xsl:stylesheet> 主程序 using Sy......

阅读全文(1831) | 评论:0

为样式表单传递参数 xslt(2007-11-03 16:38:00)

摘要:xml文件: <?xml version="1.0" encoding="utf-8" ?>
<order>
  <book ISBN="10-861003-324">
    <title>the handmaid's tale</title>
    <price>19.95</price>
  </book>
  <cd ISBN="2-3631-4">
    <title>americana</title>
    <price>16.95</price>
  </cd>
</order> xslt文件: <?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:param name="date"/>
  <xsl:template match="/">
  <order>
    <date>
      <xsl:value-of select="$date"/>
    </date>
    <total>
      <xsl:value-of select="sum(//price)"/>
    </total>......

阅读全文(2617) | 评论:0

获取属性集合xml(2007-11-02 15:52:00)

摘要:using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Collections; namespace namednodemap
{
    class Program
    {
        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<book genre='novel' publicationdate='1997'><title>pride and prejudice</title></book>");
            XmlAttributeCollection attrcoll = doc.DocumentElement.Attributes;
            XmlAttribute attr = (XmlAttribute)attrcoll.GetNamedItem("genre");
            attr.Value = "fict......

阅读全文(2037) | 评论:0

SelectNodes(2007-11-02 15:14:00)

摘要:using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Collections; namespace SelectNodes
{
    class Program
    {
        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(@"E:\c#\c#_windows程序设计学生成绩信息.xml");
           
            XmlNodeList nodelist;
            XmlElement root = doc.DocumentElement;
            nodelist = root.SelectNodes("student/name");
        &nb......

阅读全文(4117) | 评论:0

InnerXml OuterXml InnerText(xml)(2007-10-31 22:08:00)

摘要:xml 文件如下: <?xml version="1.0" encoding="GBK"?>
<studentlist>
  <student>
    <name>吴贻龙</name>
    <num>8000103124</num>
    <age>21</age>
    <sex>male</sex>
    <englishscores>91</englishscores>
    <xmlscores>80</xmlscores>
    <umlscores>85</umlscores>
    <scholarship>特等</scholarship>
  </student>
</studentlist> 程序如下:   using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Collections; namespace oXmlNode
{
    class Program
    {
        static void Main(string[] args)
        {
      ......

阅读全文(3344) | 评论:0

判断dataset是否为空(2007-10-29 22:10:00)

摘要:应该先判断是否数据集为空(查询出错时),接着判断表中的行数是否为零(查询未出错且行数是否为零),否则容易出错,
例如:先判断myDataSet.Tables[0].Rows.Count==0时,如果查询出错时,此时myDataSet为null,也就没有table,所以会报错。 故应该这样判断
if (myDataSet == null || myDataSet.Tables[0].Rows.Count == 0)
{
//为空时进行处理
}
else
{
//不为空时处理
}
“||”和“&&”操作符先判断第一个条件,不满足后接着判断下一条件,但如果上面顺序调换在myDataSet为null时则会出错,即先判断大的条件,接着判断小的条件
......

阅读全文(3313) | 评论:0

xsd架构生成类文件(2007-10-16 13:04:00)

摘要:问题描叙:

1、我们在项目一中添加一个“DataSetOne.xsd”,注意是数据集类型的,然后建立一个如下的Schema,点“保存”,可以看到多出一个DataSetOne.cs类,这是IDE自动生成的


图一:创建含DataSet类的Xml Schema


图2:编辑Schema


图3:Schema将自动生成DataSetOne.cs类

2、然后你需要在另外一个项目中也使用这个DataSetOne.xsd ,就把以下几个文件拷贝到另外一个项目中,并“包含到项目中来”


图5:这个时候,你发现Schema不自动生成DataSetOne.cs了,而且文件跑到外面一层去了


解决方案:



图5:解决方案,先删除项目中的DataSetOne.cs文件,再右键点击DataSetOne.xsd,选择“属性”,在“自定义工具”栏上填写上“MSDataSetGenerator”,然后点保存即可 ......

阅读全文(4543) | 评论:0