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 ...
随机推荐
- DuiLib DirectUI 界面库
国内首个开源 的directui 界面库,开放,共享,惠众,共赢,遵循bsd协议,可以免费用于商业项目,目前支持Windows 32 .Window CE.Mobile等平台. Duilib 是一款强 ...
- fdisk分区自动挂载
理解/etc/fstab文件配置 首先打开这个文件我们查看下本身内容 vi /etc/fstab 或者 vim /etc/fstab 2 介绍下fstab配置 文件配置每一行属于一个配置,每个 ...
- ICMP TYPE CODE
TYPE CODE Description Query Error 0 0 Echo Reply——回显应答(Ping应答) x 3 0 Network Unreachable——网络不可达 ...
- bzoj 4401 块的计数 思想+模拟+贪心
块的计数 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 455 Solved: 261[Submit][Status][Discuss] Descr ...
- eclipse 搭建ruby环境
第一步:获取RDT,http://sourceforge.net/projects/rubyeclipse/files/ 解压该文件,获得features和plugins两个文件夹,将这两个文件夹分别 ...
- 集合 Properties 的 简单例子(Spring)
Java代码: package com.ioc; import java.util.Properties; public class Student { private String name; pr ...
- 降雨量 BZOJ 1067
降雨量 [问题描述] 我们常常会说这样的话:“X年是自Y年以来降雨量最多的”.它的含义是X年的降雨量不超过Y年,且对于任意Y<Z<X,Z年的降雨量严格小于X年.例如2002,2003,20 ...
- Android网络编程之HttpClient运用
Android网络编程之HttpClient运用 在 Android开发中我们经常会用到网络连接功能与服务器进行数据的交互,为此Android的SDK提供了Apache的HttpClient来方便我们 ...
- 转载自csdn http://blog.csdn.net/ithomer/article/details/6035627 Vim的分屏功能
Vim的分屏功能 目录(?)[+] 本篇文章主要教你如何使用 Vim 分屏功能 分屏启动Vim 使用小写的o参数来上下分屏(横向分屏). vim -on file1 file2 ... 使用大写的O参 ...
- 487. Max Consecutive Ones II
Given a binary array, find the maximum number of consecutive 1s in this array if you can flip at mos ...