C# does not contain a constructor that takes no parameter
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的更多相关文章
- C# "error CS1729: 'XXClass' does not contain a constructor that takes 0 arguments"的解决方案
出现这种错误的原因时,没有在子类的构造函数中指出仅有带参构造函数的父类的构造参数. 具体来讲就是: 当子类要重用父类的构造函数时, C# 语法通常会在子类构造函数后面调用 : base( para_t ...
- Base class does not contain a constructor that takes '0' argument
刚刚在写一段直播室网站中的一段程序遇,突然遇到一个错误,如下 'TVLLKBLL.BaseClass' does not contain a constructor that takes 0 argu ...
- 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 最近在做服务的 ...
- Android 自定义View及其在布局文件中的使用示例
前言: 尽管Android已经为我们提供了一套丰富的控件,如:Button,ImageView,TextView,EditText等众多控件,但是,有时候在项目开发过程中,还是需要开发者自定义一些需要 ...
- JAVA基础 Exception, Error
转载请附上本文地址: http://www.cnblogs.com/nextbin/p/6219677.html 本文参考: JAVA源码 http://swiftlet.net/archives/9 ...
- 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 ...
- Beginning Scala study note(3) Object Orientation in Scala
1. The three principles of OOP are encapsulation(封装性), inheritance(继承性) and polymorphism(多态性). examp ...
- ListFragment源码 (待分析)
/* * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Apache License, Versi ...
- Windows Service--Write a Better Windows Service
原文地址: http://visualstudiomagazine.com/Articles/2005/10/01/Write-a-Better-Windows-Service.aspx?Page=1 ...
随机推荐
- SQL 优化案例之变更表结构
从慢日志报表中看到一条很长的SQL select id from myinfo and (( SUBSTRING_INDEX(location_axis, ) ) ) ), '$%') ) or ( ...
- 刷题总结——愤怒的小鸟(NOIPDAY2T3)
题目: 题目背景 NOIP2016 提高组 Day2 T3 题目描述 Kiana 最近沉迷于一款神奇的游戏无法自拔.简单来说,这款游戏是在一个平面上进行的. 有一架弹弓位于 (0,0) 处,每次 Ki ...
- uva 11916 解模方程a^x=b (mod n)
Emoogle Grid You have to color an M x N ( 1M, N108) two dimensional grid. You will be provided K ...
- ElasticSearch API 之 DELETE
删除API,可以根据特定的ID删除文档. $ curl -XDELETE 'http://localhost:9200/website/blog/AVbkih8AltSLRRB7XAun' 会返回下面 ...
- spring--路由
@RestController: Spring4之后新加入的注解,原来返回json需要@ResponseBody和@Controller配合. 即@RestController是@ResponseBo ...
- 带你学Node系列之express-CRUD
前言 hello,小伙伴们,我是你们的pubdreamcc,本篇博文出至于我的GitHub仓库node学习教程资料,欢迎小伙伴们点赞和star,你们的点赞是我持续更新的动力. GitHub仓库地址:n ...
- CODEVS_1034 家园 网络流 最大流
原题链接:http://codevs.cn/problem/1034/ 题目描述 Description 由于人类对自然的疯狂破坏,人们意识到在大约2300年之后,地球不能再居住了,于是在月球上建立了 ...
- Linux出现cannot create temp file for here-document: No space left on device的问题解决
在终端输入:cd /ho 按tab键时,显示错误: bash: cannot create temp file for here-document: No space left on device 这 ...
- dropwatch 网络协议栈丢包检查利器 与 火丁笔记
http://blog.yufeng.info/archives/2497 源码:http://git.fedorahosted.org/cgit/dropwatch.git http://blog. ...
- MySQL 索引及其用法
一.索引的作用 一般的应用系统,读写比例在10:1左右,而且插入操作和一般的更新操作很少出现性能问题,遇到最多的,也是最容易出问题的,还是一些复杂的查询操作,所以查询语句的优化显然是重中之重. 在数据 ...