Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
1.	using System;
2.	namespace Examples
3.	{
4.		 class Program
5.	{
6.		public static void Main(string[]args)
7.		{
8.			Laptop Lenovo=new Laptop("Lenovo");
9.			Lenovo.Price("$");
10.			Lenovo.Processor("i");
11.			Lenovo.Ram(2);
12.			Lenovo.HDD(500);
13.			
14.			Laptop Dell=new Laptop("Dell");
15.			Dell.Price("$");
16.			Dell.Processor("i");
17.			Dell.Ram(4);
18.			Dell.HDD(1);
19.			
20.			Laptop Sony=new Laptop("Sony");
21.		    Sony.Price("$");
22.			Sony.Processor("i");
23.			Sony.Ram(8);
24.			Sony.HDD(1);
25.			
26.			
27.		}
28.	}
29.	class Laptop:LaptopBase
30.	{
31.		public  LaptopBase(String LaptopName):base(LaptopName)
32.		{
33.			this.LaptopBase=LaptopName;
34.		
35.		  	} 
36.		class LaptopBase
37.		{
38.			public LaptopBase(String LaptopName)
39.			{
40.				Console.WriteLine(" "+LaptopName);
41.			}
42.		
43.		
44.		public void Price()
45.		{
46.		Console.WriteLine("$"+ 1000,"$"+2000,"$"+3000);
47.		}
48.	public void Processor()
49.	{
50.	Console.WriteLine("i"+3,"i"+5,"i"+7);
51.	}
52.		public void Ram()
53.		{
54.			Console.WriteLine(2+"GB",4+"GB",8+"GB");
55.		}
56.		public void HDD()
57.		{
58.			Console.WriteLine(500+"GB",1+"TB",1+"TB");
59.		}
60.	}
61.			}
62.	}

[edit]Code block added - OriginalGriff[/edit]

What I have tried:

main.cs(31,10): error CS1520: Class, struct, or interface method must have a return type
Posted
Updated 10-Nov-17 2:47am
v2

1 solution

Look at the error message, and at your code:
main.cs(31,10): error CS1520: Class, struct, or interface method must have a return type

main.cs(31,10):
This means the error is on line 31, column 10, of the file "main.cs"
So look at that line:
C#
29.	class Laptop:LaptopBase
30.	{
31.		public  LaptopBase(String LaptopName):base(LaptopName)
32.		{
33.			this.LaptopBase=LaptopName;

That's a constructor: but it's a constructor of the base class, not the actual class. As a result, your get this error:
error CS1520: Class, struct, or interface method must have a return type
Because you can only create a constructor in the class that it refers to.
Probably, you need to declare a Laptop constructor, not a LaptopBase - which would get rid of that error, but...
1) LaptopBase is a class, not a variable, so you can't assign a string to it.
2) Declaring the base class as part of the class that derives from it is ... um ... odd. Very odd. How do you expect other classes to easily derive from LaptopBase if it's part of the Laptop class?

I think you need to rethink what you are trying to do here, and reread your course notes - that code very much looks like the "guess and hope it works" school of coding, and that isn't a good design strategy!
 
Share this answer
 
Comments
parth cool 15-Nov-17 4:47am    
Thanks a ton!!!
OriginalGriff 15-Nov-17 4:55am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900