您的位置:首页 > 编程语言 > C#

C#课堂笔记-2013-10-25

2013-10-25 11:26 316 查看
省纸了。。。。



课件内容:

====================================================================================================================================



所有类型的基类型,System.Object

Class Employee{}//隐式

Class Employee:System.Object{}//显式

等效

System.Object的公有方法

Equals()//两个object实例是否相等

GetHashCode()//

ToString()//返回类型全名this.GetType().FullName.ToString

GetType()//

ReferenceEquals()//是否相同实例













此段代码关于上映射(up cast)和下映射(down cast)

is 和 as 的用法

A->B->C->D 从爷爷到子孙

B(C\D) is A

A is not B(CD)







using System;
class Employee { }
class Manager : Employee { }
class App
{
    public static void Main()
    {
        Manager m = new Manager();
        PromoteEmployee(m);
        DateTime newYears = new DateTime(2004, 1, 1);
        PromoteEmployee(newYears);
    }
    public static void PromoteEmployee(Object o)
    {
        Employee e = (Employee)o;
    }
}

using相当于java的import,VB的imports

using CNProduct =CompanyName.Product;//using添加别名



C#中的Enum,目测和C++一样。(Char以外的任何类型都可,默认是int32)

枚举隐式派生自System.Enum.

System.enum继承自system.ValueType

====================================================================================================================================











第二次实验(什么时候有第一次?):

课下作业么:

tips:





打开英文文本文件,count单词数(空格,标点(那么多种标点怎么if))。统计单词出现频率(所有的?动态数组?)






using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace StreamWrite{
    class Program    {
/*        static void Main(string[] args)        {
            try{
                FileStream aFile = new FileStream("Log.txt", FileMode.OpenOrCreate);
                StreamWriter sw = new StreamWriter(aFile);
                bool truth = true;                // Write data to file.
                sw.WriteLine("Hello to you.");
                sw.WriteLine("It is now {0} and things are looking good.",                    DateTime.Now.ToLongDateString());
                sw.Write("More than that,");
                sw.Write(" it's {0} that C# is fun.", truth);
                sw.Close();            
            }catch (IOException ex)            {
                Console.WriteLine("An IOException has been thrown!");
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
                return;
            }
        }
的*/
        //读取文件,StreamReader对象
        static void Main(string[] args)
        {
            string strLine;
            try
            {
                FileStream aFile = new FileStream("Log.txt", FileMode.Open);
                StreamReader sr = new StreamReader(aFile);
                strLine = sr.ReadLine();            //Read data in line by line 一行一行的读取      
                while (strLine != null)
                {
                    Console.WriteLine(strLine);
                    strLine = sr.ReadLine();
                }
                sr.Close();
            }
            catch (IOException ex)
            {
                Console.WriteLine("An IOException has been thrown!");
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
                return;
            }
        }

    }
}




详细操作需要

System.IO.StreamReader
的 10个构造函数、20个方法、1个字段和3个属性





百度搜索 “ C# 读取 文件 统计 单词”
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: