Click here to Skip to main content
15,910,118 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
namespace objectandclass
{
    public class Weapon
    {
        public string title;
        public string colour;
        public int ammo;
    }
}


namespace objectandclass
{
    class Program
    {
        static void Main(string[] args)
        {
            Weapon weapon1 = new Weapon();
            weapon1.title = "CZ Scorpion EVO 3";
            weapon1.colour = "gold";
            weapon1.ammo = 30;

            Console.WriteLine(weapon1.ammo);
            Console.ReadKey();
        }
    }
}


I can not run the program because of
CS0115 C# '': no suitable method found to override
. Dunno why. It is almost exactly the same as in tutorial vid. I changed just names.

What I have tried:

Component1.Dispose(bool). Dunno what that means. What is the problem in my code?
Posted
Updated 24-Jan-20 20:06pm
Comments
Richard MacCutchan 25-Jan-20 9:03am    
There must be something different in the code you are using and what you have posted. I just compiled and ran the above code with no errors.

Copy/Paste of code into VS2019 works fine.

Take a look at the 'Error list'. To the right is the line number of the error, or double-click on the error, and VS will move the cursor to where the error is. Take a look at the line of code where the cursor is, and see what's going on there. Also check the lines leading up to where the error is flagged, checking for missed semicolons, quotes, etc.

Other than that, maybe its something in the code that you're not showing us. What's Component1.Dispose(bool) got to do with anything in the code snippets, above?
 
Share this answer
 
Comments
sOwlO 25-Jan-20 0:10am    
Error message is for that line of code: Console.WriteLine(weapon1.ammo);
It have some trouble with the .ammo
If I write there .title it shows me the same error.
Can't tell you. The code you posted cannot possibly generate the error you're posting. Also, typically, you would also get the file and line number that generated the error, which you didn't post.

So, there's stuff about your code you haven't told us, nor posted.
 
Share this answer
 
Comments
sOwlO 25-Jan-20 0:11am    
Im not hiding anything! :D Console.WriteLine(weapon1.ammo); is the "trouble line". cant read the .ammo
Tryed to switch that to .title and .colour and still the same error message.
Dave Kreskowiak 25-Jan-20 11:19am    
Then you're going to have to start from scratch and recreate the project. There's something in the the project outside of what you posted that's causing this.
sOwlO 25-Jan-20 14:06pm    
@Dave You are right. I added "component class" instead of "class". Thank you :)
The error message is pretty clear:
no suitable method found to override
And since you specify the line as:
C#
Console.WriteLine(weapon1.ammo);
I'd guess that you started out with a blank file, and just added that code - so you are missing a using statement:
C#
using System;

Or you have not got the required references in your project.

If it's not clear from that, go back to where you got the tutorial video, and ask there. Chances are this is a YouTube jobbie, and frankly, they are nearly all total garbage produced by people who have no idea how to make a video, and no real idea what they are doing with the code either ...
Asking them is a good way to find out: if they reply with useful information, then they might be taking it seriously and know what they are doing. If they don't (and most won't because they can't) then you are there for the views and to get subscriptions. Go elsewhere.
 
Share this answer
 
Comments
sOwlO 25-Jan-20 14:04pm    
tryed this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
Still same error. Btw. books and yt vids are main resources for learning, now.

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