方法,C#中的继承类和字符串 [英] Methods , Inheritance Class in C# and strings
问题描述
我是初学者程序员喜欢基本学习C# ,请协助我,此程序有什么问题在C#中.
在这里我创建了一个简单的程序链类或继承:我犯了什么错误?
介绍一下字符串用户值;
问候
Jeevamoorthy
{ 书 { void Main( 字符串 { 作者
= ; 标题
= ; 价格
= 50; 页面
= 350; 股票
= 13; void show() { .WriteLine( "
" ); >
.WriteLine( "书籍
信息" ); >
.WriteLine( "
图书作者:" +作者); .WriteLine( "书
标题" :+标题); .WriteLine( "
图书价格:" +价格); .WriteLine( "
页数:" +页); .WriteLine( "
图书库存:" 股票); 跨度> .ReadLine(); .Read(); } HardwareBook :
{ 硬件标题
= ; 出版商
= ; void showdata() { 系统. .WriteLine( ); >
系统. .WriteLine( ); 系统. .WriteLine( + hardwareTitle); 系统. .WriteLine( +发布者); 系统. .WriteLine( ); >
.ReadLine(); .Read(); } } SoftwareBook :
{ SoftwareName
= ; softwareVersion
= ; void showdetails() { show(); .WriteLine( "软件
图书信息" ); .WriteLine( "软件
名称:" + SoftwareName); 跨度> .WriteLine( "软件
版本:" + softwareVersion); 跨度> .WriteLine( "
" ); >
} 静态
{ h
=
span style ="font-size:small"> s
=
s.showdetails(); h.showdata(); } } } } } 我已经更正了您的代码,使其可以正常工作,您可以将自己的代码与我的代码进行比较,以查看自己的工作错误的.我不确定您到底想做什么(我想是继承),所以如果您有任何疑问,请告诉我. Hi, I beginner to programmer like Basic Learn the C# , Please kindly assist to me , what is issue on this program in C#. Here it is I created the Program a simple Chain Class or Inheritance : And What were the mistake I did? Tell about the strings user value; Regard Jeevamoorthy usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingSystem.Threading.Tasks; namespaceBooksTreasure { classBook { staticvoidMain(string[]
args) { Stringauthor
= "steve"; Stringtitle
= "Handbook"; intprice
= 50; intpages
= 350; intstock
= 13; publicvoidshow() { Console.WriteLine("
"); Console.WriteLine("Books
Information"); Console.WriteLine("
Book Author: "+ author); Console.WriteLine("Book
Title": + title); Console.WriteLine("
Book Price:"+ price); Console.WriteLine("
Number of Pages: "+ pages); Console.WriteLine("
Book Stock:"Stock); Console.ReadLine(); Console.Read(); } classHardwareBook:
Book { StringhardwareTitle
= "Printers"; Stringpublisher
= "Tom Wilkins"; publicvoidshowdata() { System.Console.WriteLine("
"); System.Console.WriteLine("
Hardware Books Informations"); System.Console.WriteLine("
Hardware Title:"+ hardwareTitle); System.Console.WriteLine("
Publisher Name"+ publisher); System.Console.WriteLine("
"); Console.ReadLine(); Console.Read(); } } classSoftwareBook:
Book { StringSoftwareName
= "Windows"; StringsoftwareVersion
= "Mary Peterson"; publicvoidshowdetails() { show(); Console.WriteLine("Software
Books Information"); Console.WriteLine("Software
Name:"+ SoftwareName); Console.WriteLine("Software
Version:"+ softwareVersion); Console.WriteLine("
"); } publicstaticvoidmain
(Stringargs [ ]) { HardwareBookh
= newBooksTreasure.Book.HardwareBook(); SoftwareBooks
= newBooksTreasure.Book.SoftwareBook(); s.showdetails(); h.showdata(); } } } } } I have corrected your code so that it is working, you can compare your code to mine to see what you did wrong. I am not sure what exactly you are trying to do (I suppose inheritance) so if you have any questions let me know. 这篇关于方法,C#中的继承类和字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
使用系统;
命名空间BooksTreasure
{
课本
{
字符串作者="steve";
字符串标题=手册";
整型价格= 50;
int页数= 350;
内部库存= 13;
公共无效的show()
{
Console.WriteLine(");
Console.WriteLine("Books Information");
Console.WriteLine(书作者:" +作者);
Console.WriteLine(书名:"和书名);
Console.WriteLine("Book Price:" + price);
Console.WriteLine(页数:" +页数);
Console.WriteLine(书库:" +书库);
}
}
class HardwareBook:书
{
字符串hardwareTitle =打印机";
字符串发布者="Tom Wilkins";
公共无效的showdata()
{
Console.WriteLine(");
Console.WriteLine(硬件书籍信息");
Console.WriteLine(硬件标题:" + hardwareTitle);
Console.WriteLine(发布者名称" +发布者);
Console.WriteLine(");
}
}
类SoftwareBook:硬件手册
{
字符串softwareName ="Windows";
字符串软件版本=玛丽·彼得森";
公共无效的showdetails()
{
展示();
Console.WriteLine(");
Console.WriteLine(软件书籍信息");
Console.WriteLine(软件名称:" +"softwareName");
Console.WriteLine(软件版本:" + softwareVersion);
Console.WriteLine(");
}
}
类DisplayData
{
公共静态void Main(String [] args)
{
SoftwareBook s =新的SoftwareBook();
s.showdetails();
s.showdata();
Console.ReadLine();
}
}
}
using System;
namespace BooksTreasure
{
class Book
{
String author = "steve";
String title = "Handbook";
int price = 50;
int pages = 350;
int stock = 13;
public void show()
{
Console.WriteLine(" ");
Console.WriteLine("Books Information");
Console.WriteLine("Book Author: " + author);
Console.WriteLine("Book Title: " + title);
Console.WriteLine("Book Price:" + price);
Console.WriteLine("Number of Pages: " + pages);
Console.WriteLine("Book Stock:" + stock);
}
}
class HardwareBook : Book
{
String hardwareTitle = "Printers";
String publisher = "Tom Wilkins";
public void showdata()
{
Console.WriteLine(" ");
Console.WriteLine("Hardware Books Informations");
Console.WriteLine("Hardware Title:" + hardwareTitle);
Console.WriteLine("Publisher Name" + publisher);
Console.WriteLine(" ");
}
}
class SoftwareBook : HardwareBook
{
String softwareName = "Windows";
String softwareVersion = "Mary Peterson";
public void showdetails()
{
show();
Console.WriteLine(" ");
Console.WriteLine("Software Books Information");
Console.WriteLine("Software Name: " + softwareName);
Console.WriteLine("Software Version: " + softwareVersion);
Console.WriteLine(" ");
}
}
class DisplayData
{
public static void Main(String[] args)
{
SoftwareBook s = new SoftwareBook();
s.showdetails();
s.showdata();
Console.ReadLine();
}
}
}