思胜C#学习第四天

1、  复习,对象object 的问题,类的问题 template模板 类在图纸上的设计 

利用class类 创造出一个对象object 就是class object = new class();

设计师就是要搭建这些类

类里面有两种内容,数据与方法 

封装的问题 就是封好数据变量 装好方法(行为、函数,做些什么操作,注意方法名的首字母要大写,构造函数的作用于重载,默认、普通)

继承、

多态

高级语言是更加贴近人的,所以在C与C++里面才自动执行析构函数,在C#会自动全部初始化为0

 

系统功能,api函数问题 msdn  就是系统内部的API函数 直接调用  而掌握也是很重要的

2、  用类来归类 但是有信息流分析法 事务分析法 动作分析法

第一个类 object 基类 万物都是类 是一个超类  类型层次的根

派生类  public class Piont:Object

继承关系 父类的特征可以被子类继承 Point 分两个  一个是object的方法与数据

还有一部分是属于自己的

派生类重写  基类里面有一个虚方法ToString(); override 重写掉基类的方法

using System;

 

// The Point class is derived from System.Object.

class Point :Object

{

    public int x, y;

 

    public Point(int x, int y)

    {

        this.x = x;

        this.y = y;

    }

 

    public override bool Equals(object obj)

    {

        // If this and obj do not refer to the same type, then they are not equal.

        if (obj.GetType() != this.GetType()) return false;

 

        // Return true if  x and y fields match.

        Point other = (Point) obj;

        return (this.x == other.x) && (this.y == other.y);

    }

 

    // Return the XOR of the x and y fields.

    public override int GetHashCode()

    {

        return x ^ y;

    }

 

    // Return the point's value as a string.

    public override String ToString()

    {

        return String.Format("({0}, {1})", x, y);

}

 

public override string ToString()

{

    return base.ToString();

}

 

 

    // Return a copy of this point object by making a simple field copy.

    public Point Copy()

    {

        return (Point) this.MemberwiseClone();

    }

}

 

public sealed class App {

    static void Main()

    {

        // Construct a Point object.

        Point p1 = new Point(1,2);

 

        // Make another Point object that is a copy of the first.

        Point p2 = p1.Copy();

 

        // Make another variable that references the first Point object.

        Point p3 = p1;

 

        // The line below displays false because p1 and p2 refer to two different objects.

        Console.WriteLine(Object.ReferenceEquals(p1, p2));

 

        // The line below displays true because p1 and p2 refer to two different objects that have the same value.

        Console.WriteLine(Object.Equals(p1, p2));

 

        // The line below displays true because p1 and p3 refer to one object.

        Console.WriteLine(Object.ReferenceEquals(p1, p3));

 

        // The line below displays: p1's value is: (1, 2)

        Console.WriteLine("p1's value is: {0}", p1.ToString());

    }

}

 

// This code example produces the following output:

//

// False

// True

// True

// p1's value is: (1, 2)

//

3、  熟悉派生类的重写:

Override string ToString()

4、  类的对象问题

5、  有值有引用对象),而堆就是引用实例栈sp(仅仅是值,还有引用实例的名字P) 寄存器  外面有一个叫堆 寄存器  栈空间小 很容易溢出  数据量大的时候就放在堆里  那么哪些咋放? 数据类型的问题 分为 值类型 整形的类型就放在栈 与 引用类型  类类型 放在堆里面 方法都是在类里面  还有一个实例的名字P 会放在栈里面,对堆里面P所包含的东西 进行引用  在new的时候 就根据方法的大小划分初始存储大小 就先赋值  再进行构造函数(在堆里面)  然后才道 栈里面设置一个P作为对象的引用 p1.x 与p2.x不同

6、判断对象的类型,那么就是叫号 hashcode 对每一个对象都有一个号GetHashCode 用作特殊类型的GetHashCode 方法的默认实现不保证针对不同的对象返回唯一值。而且,.NET Framework 不保证 GetHashCode 方法的默认实现以及它所返回的值在不同版本的 .NET Framework 中是相同的。因此,在进行哈希运算时,该方法的默认实现不得用作唯一对象标识符。

7、GetHashCode 方法可以由派生类型重写。值类型必须重写此方法,以提供适合该类型的哈希函数和在哈希表中提供有用的分布。为了获得最佳结果,哈希代码必须基于实例字段或属性(而非静态字段或属性)的值。利用hashcode来判断是否是同一个对象1

重写解决问题重出的问题,就是利用重写hashcode 给x y搞一个组合hashcode进行判断

就是对系统hanshcode而言 的确是会因为p1 p2的不同 而生成的x+y的结果也是不同,但是现在我们就可以重写 ,令到 不关于P1P2 而且还要活跃思维定义一个顺序

 

8、  解决题目的问题  现在要每一个问题对应一个对象 平P1到P2

 

9、ItemGroup添加跟中 用txt打开解决方案文件

Microsoft Visual Studio Solution File, Format Version 11.00

# Visual Studio 2010

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApplication1", "ConsoleApplication1\ConsoleApplication1.csproj", "{5D299E12-E07C-4B77-8E13-25CEFD393C7C}"

EndProject

Global

     GlobalSection(SolutionConfigurationPlatforms) = preSolution

          Debug|x86 = Debug|x86

          Release|x86 = Release|x86

     EndGlobalSection

     GlobalSection(ProjectConfigurationPlatforms) = postSolution

          {5D299E12-E07C-4B77-8E13-25CEFD393C7C}.Debug|x86.ActiveCfg = Debug|x86

          {5D299E12-E07C-4B77-8E13-25CEFD393C7C}.Debug|x86.Build.0 = Debug|x86

          {5D299E12-E07C-4B77-8E13-25CEFD393C7C}.Release|x86.ActiveCfg = Release|x86

          {5D299E12-E07C-4B77-8E13-25CEFD393C7C}.Release|x86.Build.0 = Release|x86

     EndGlobalSection

     GlobalSection(SolutionProperties) = preSolution

          HideSolutionNode = FALSE

     EndGlobalSection

EndGlobal

10、用txt打开项目文件

  <ItemGroup>

    <Reference Include="System" />

    <Reference Include="System.Core" />

    <Reference Include="System.Xml.Linq" />

    <Reference Include="System.Data.DataSetExtensions" />

    <Reference Include="Microsoft.CSharp" />

    <Reference Include="System.Data" />

    <Reference Include="System.Xml" />

  </ItemGroup>

  <ItemGroup>

    <Compile Include="Class1.cs" />

    <Compile Include="Program.cs" />

    <Compile Include="Properties\AssemblyInfo.cs" />

  </ItemGroup>

  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.

       Other similar extension points exist, see Microsoft.Common.targets.

  <Target Name="BeforeBuild">

  </Target>

  <Target Name="AfterBuild">

  </Target>

  -->

 

11、开发注意事项  还要注意管理员方法与客户方法

喜欢问题 从 问题 考试  就是划分好对象 就可以让程序员关注对应的负责部分,便于维护,减少工作困难度

 

12、试卷的问题,保存试题的时候就必须要实例化10个问题吗?  不一定,我们可以实例化一个新的数组,利用下标来区分

private Question[] questions;

 

public Page(int number, int nan)

{

    Console.WriteLine("本卷考题有 {0} 条",number);

    questions=new Question[10];

}

13、利用特殊值 监控 三种循环的特点 执行与判断的先后的问题

 

14、利用哨兵模式 与 内外判断模式 可以减少bug率

方法调用了两次,就是可以把动作放在while里面,要由语句合并的思维,在实际开发中要进行一定的语句合并

一个方法不要超过66行 就是一页代码  paper里面有questions questions里面有question

然后 question里面有显示题目与判断对于错的方法

女孩 http://www.hainvhai.com

保温杯 http://www.ibaowenbei.com

转载于:https://www.cnblogs.com/www-dyping-com/archive/2013/04/13/3018639.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值