Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Theres no Error display but theres also No Output. This is just a simple and my first time doing this. I used visual studio 2019. Please Help Me


Heres the code: and also the link for the picture of my screen(
https://docs.google.com/document/d/18Do7hi2QKByRGR6UmM-SBL0I1wsdFeoF/edit?usp=sharing&ouid=116166790128347921039&rtpof=true&sd=true

)

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace HelloObjects
{

    class Greeter
    {
        public void Greet()
        {
            Console.WriteLine("Hello object world!");
        }
    }
}


What I have tried:

Ive tried changing the settings and checking the codes from yt. Please Help me how to display the output
Posted
Updated 13-Sep-21 3:06am
v3
Comments
Member 15329613 13-Sep-21 9:01am    
You have to call that code. You probably have a Main() function somewhere so you would create an instance of your Greeter class and then call Greet.
PIEBALDconsult 13-Sep-21 9:02am    
Well, with no main method...

1 solution

First of all you do not do anything in your Main method which is the entry point of your programme.

You defined a class named Greeter but you never us it.
A class ist nothing but a prototype for an object.

In order to see "Hello object world" on your screen
you must

1) Create an instance aka object of your class like this
C#
var myGreeter = new Greeter();

2) Then you must call the Greet method like this:
C#
myGreeter.Greet();

Moreover I would like to recommend you this tutorial:
http://www.charlespetzold.com/dotnet/DotNetBookZero11.pdf[^]
 
Share this answer
 
v3
Comments
BillWoodruff 13-Sep-21 10:39am    
+5
TheRealSteveJudge 14-Sep-21 1:59am    
Thank you, Bill!

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