C# 中子类要重用父类的构造函数时, 一般会在子类构造函数后面调用 : base(paratype, para).

如果父类有一个參数个数为1的构造函数, 没有 0 參构造函数。 子类想要重用这个构造函数, 如果没有写 :base(paratype, para), 就会有这个错误。

由于假设没写, VS 会觉得子类是继承父类的 0 參构造函数, 可是由于父类并未定义 0 參构造函数。 所以就会报错。

另外, 能够在base()中调用一个静态方法来改动子类构造函数的參数在传递给父类构造函数。 如:

class ParentClass
{
public ParentClass(string Name)
{}
}
class ChildClass
{
public ChildClass(string firstName, string familyName):base(CombineName(firstName, familyName)
{}
static string ConbineName(string firstName, string familyName)
{return string.Format("{0},{1}", firstName, familyName);
}

C# does not contain a constructor that takes no parameter的更多相关文章

  1. C# "error CS1729: 'XXClass' does not contain a constructor that takes 0 arguments"的解决方案

    出现这种错误的原因时,没有在子类的构造函数中指出仅有带参构造函数的父类的构造参数. 具体来讲就是: 当子类要重用父类的构造函数时, C# 语法通常会在子类构造函数后面调用 : base( para_t ...

  2. Base class does not contain a constructor that takes '0' argument

    刚刚在写一段直播室网站中的一段程序遇,突然遇到一个错误,如下 'TVLLKBLL.BaseClass' does not contain a constructor that takes 0 argu ...

  3. Unable to find a constructor that takes a String param or a valueOf() or fromString() method

    Unable to find a constructor that takes a String param or a valueOf() or fromString() method 最近在做服务的 ...

  4. Android 自定义View及其在布局文件中的使用示例

    前言: 尽管Android已经为我们提供了一套丰富的控件,如:Button,ImageView,TextView,EditText等众多控件,但是,有时候在项目开发过程中,还是需要开发者自定义一些需要 ...

  5. JAVA基础 Exception, Error

    转载请附上本文地址: http://www.cnblogs.com/nextbin/p/6219677.html 本文参考: JAVA源码 http://swiftlet.net/archives/9 ...

  6. Beginning Scala study note(8) Scala Type System

    1. Unified Type System Scala has a unified type system, enclosed by the type Any at the top of the h ...

  7. Beginning Scala study note(3) Object Orientation in Scala

    1. The three principles of OOP are encapsulation(封装性), inheritance(继承性) and polymorphism(多态性). examp ...

  8. ListFragment源码 (待分析)

    /* * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Apache License, Versi ...

  9. Windows Service--Write a Better Windows Service

    原文地址: http://visualstudiomagazine.com/Articles/2005/10/01/Write-a-Better-Windows-Service.aspx?Page=1 ...

随机推荐

  1. Ubuntu Software Center has closed unexpectly解决方案

    打开软件中心Ubuntu Software Center的时候 出现crash report :The application Ubuntu Software Center has closed un ...

  2. 【JavaScript 14—学习总结】:从小事做起

    导读:花了将近两个月,JavaScript的学习视频算是做完了.里面的例子,都敲过一遍,但有少数的几个就是实现不了,比如:百度分享侧栏随着滚动条移动:菜单切换只对第一个起作用等,也就先放着了.现在,就 ...

  3. iOS学习笔记13-网络(二)NSURLSession

    在2013年WWDC上苹果揭开了NSURLSession的面纱,将它作为NSURLConnection的继任者.现在使用最广泛的第三方网络框架:AFNetworking.SDWebImage等等都使用 ...

  4. 洛谷P3759 - [TJOI2017]不勤劳的图书管理员

    Portal Description 给出一个\(1..n(n\leq5\times10^4)\)的排列\(\{a_n\}\)和数列\(\{w_n\}(w_i\leq10^5)\),进行\(m(m\l ...

  5. 济南学习 Day5 T3 晚

    回文串(palindromes) [题目描述] 判断是否能将字符串S分成三段非空回文串. [输入说明] 第一行一个整数T,表示数据组数. 对于每一个组,仅包含一个由小写字母组成的串. [输出说明] 对 ...

  6. gdbt原理解析

    链接: http://note.youdao.com/noteshare?id=aeb1c7a30c5f4b70e3fff51f28ee5c47 懒得复制到这里了,一开始是在有道云笔记上写的,这里的公 ...

  7. POJ 2185 Milking Grid [二维KMP next数组]

    传送门 直接转田神的了: Milking Grid Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6665   Accept ...

  8. 标准C程序设计七---16

    Linux应用             编程深入            语言编程 标准C程序设计七---经典C11程序设计    以下内容为阅读:    <标准C程序设计>(第7版) 作者 ...

  9. 建立django博客应用及数据库模型

    1.现在就来创建我们的 Django 博客应用,我把它命名为 blog.激活虚拟环境,进入到 manage.py 文件所在的目录下,运行 python manage.py startapp blog ...

  10. 简单div遮罩

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...