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 ...
随机推荐
- Linux cp复制
复制指定目录下的全部文件到另一个目录中文件及目录的复制是经常要用到的.linux下进行复制的命令为cp.假设复制源目录 为 dir1 ,目标目录为dir2.怎样才能将dir1下所有文件复制到dir2下 ...
- ImportError: No module named ‘MySQLdb'
1.APP未注册 INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contentty ...
- HDU-4417 Super Mario,划分树+二分!
Super Mario 这个题也做了一天,思路是很清晰,不过二分那里写残了,然后又是无限RE.. 题意:就是查询区间不大于k的数的个数. 思路:裸划分树+二分答案.将区间长度作为二分范围.这个是重点. ...
- PHP中file_put_contents追加和换行的实现方法
在PHP的一些应用中需要写日志或者记录一些信息,这样的话.可以使用fopen(),fwrite()以及 fclose()这些进行操作.也可以简单的使用file_get_contents()和file_ ...
- shell的brake和continue的用法
在循环过程中,有时候需要在未达到循环结束条件时强制跳出循环,像大多数编程语言一样,Shell也使用 break 和 continue 来跳出循环. break命令 break命令允许跳出所有循环(终止 ...
- SPOJ QTREE3 Query on a tree again! ——Link-Cut Tree
[题目分析] QTREE2,一看是倍增算法,太懒了,不写了.( ̄_, ̄ ) QTREE3,树链剖分可以做,发现链上的问题LCT也很好做. 要是子树问题貌似可以DFS序. 然后就成LCT模板题了. 考前 ...
- 刷题总结——飞扬的小鸟(NOIP2014提高组)
题目: 题目背景 NOIP2014 提高组 Day1 试题. 题目描述 Flappy Bird 是一款风靡一时的休闲手机游戏.玩家需要不断控制点击手机屏幕的频率来调节小鸟的飞行高度,让小鸟顺利通过画面 ...
- 【二叉搜索树】hdu 3791
http://acm.hdu.edu.cn/showproblem.php?pid=3791 [注意] 是看树的形态是否一样,而不是中序遍历的结果 [Accepted] #include<ios ...
- 【2018.10.20】noip模拟赛Day3 飞行时间
今天模拟赛题目 纯考输入的傻逼题,用$scanf$用到思想僵化的我最终成功被$if$大法爆$0$了(这题只有一组$100$分数据). 输入后面那个$(+1/2)$很难$if$判断,所以我们要判两个字符 ...
- Spoj-VISIBLEBOX Decreasing Number of Visible Box
Shadowman loves to collect box but his roommates woogieman and itman don't like box and so shadowman ...