Click here to Skip to main content
15,792,510 members
Home / Discussions / C#
   

C#

 
GeneralRe: .NET 7 C# 8: using new Interface "features" ? Pin
Gerry Schmitz6-Aug-23 15:38
mveGerry Schmitz6-Aug-23 15:38 
GeneralRe: .NET 7 C# 8: using new Interface "features" ? Pin
BillWoodruff6-Aug-23 16:38
professionalBillWoodruff6-Aug-23 16:38 
GeneralRe: .NET 7 C# 8: using new Interface "features" ? Pin
harold aptroot6-Aug-23 21:55
harold aptroot6-Aug-23 21:55 
AnswerRe: .NET 7 C# 8: using new Interface "features" ? Pin
Richard Deeming6-Aug-23 23:12
mveRichard Deeming6-Aug-23 23:12 
GeneralRe: .NET 7 C# 8: using new Interface "features" ? Pin
BillWoodruff7-Aug-23 6:58
professionalBillWoodruff7-Aug-23 6:58 
GeneralRe: .NET 7 C# 8: using new Interface "features" ? Pin
Richard Deeming7-Aug-23 22:33
mveRichard Deeming7-Aug-23 22:33 
AnswerRe: .NET 7 C# 8: using new Interface "features" ? Pin
lmoelleb7-Aug-23 2:08
lmoelleb7-Aug-23 2:08 
QuestionRunning a C# class - first attempt Pin
Clive Long 20232-Aug-23 1:16
Clive Long 20232-Aug-23 1:16 
I am following the online C# tutorials here: create class and objects.

I cannot get the code to envoke the class to create an object. I have some Python knowledge but am learning C#. I am using VS 2022 community edition and running on Windows 10.

I will post the code below but what happens is the Console.WriteLine("Hello, World!"); executes but not the attempt to envoke the class.

I am guessing the code should work like this:

1. C# executable looks for
static void Main(string[] args)


2. Within this main module is the statement:
Person person = new Person();

This line should create an object person.

3. The following lines should assign values to the person object's attributes

person.Name = "Daniel";
 person.Age = 28;
 person.Haspet = true;


4. The line :

person.Greeting();


should cause the class to be called:

public void Greeting()
        {
            Console.WriteLine("Within Greeting method. Name is:" + Name +" age is:"+ Age);
            Console.ReadLine();
        }


but this code does not execute. What am I am getting wrong?

Code:
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
namespace crltemp
{
    public class Person
    {
        public string Name;
        public int Age;
        public bool Haspet;

        public void Greeting()
        {
            Console.WriteLine("Within Greeting method. Name is:" + Name + " age is:" + Age);
            Console.ReadLine();
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Person person = new Person();
            person.Name = "Daniel";
            person.Age = 28;
            person.Haspet = true;

            person.Greeting();

        }
    }
}

AnswerRe: Running a C# class - first attempt Pin
Richard Deeming2-Aug-23 1:31
mveRichard Deeming2-Aug-23 1:31 
GeneralRe: Running a C# class - first attempt Pin
Clive Long 20232-Aug-23 3:14
Clive Long 20232-Aug-23 3:14 
GeneralRe: Running a C# class - first attempt Pin
Richard MacCutchan2-Aug-23 3:27
mveRichard MacCutchan2-Aug-23 3:27 
GeneralRe: Running a C# class - first attempt Pin
Clive Long 20232-Aug-23 4:57
Clive Long 20232-Aug-23 4:57 
GeneralRe: Running a C# class - first attempt Pin
Richard MacCutchan2-Aug-23 5:10
mveRichard MacCutchan2-Aug-23 5:10 
GeneralRe: Running a C# class - first attempt Pin
OriginalGriff2-Aug-23 22:32
mvaOriginalGriff2-Aug-23 22:32 
QuestionExtract Data from PDF's Pin
Kevin Marois31-Jul-23 17:10
professionalKevin Marois31-Jul-23 17:10 
AnswerRe: Extract Data from PDF's PinPopular
OriginalGriff31-Jul-23 19:39
mvaOriginalGriff31-Jul-23 19:39 
GeneralRe: Extract Data from PDF's Pin
Kevin Marois1-Aug-23 7:59
professionalKevin Marois1-Aug-23 7:59 
GeneralRe: Extract Data from PDF's Pin
Dave Kreskowiak1-Aug-23 8:13
mveDave Kreskowiak1-Aug-23 8:13 
GeneralRe: Extract Data from PDF's Pin
Gerry Schmitz1-Aug-23 15:22
mveGerry Schmitz1-Aug-23 15:22 
GeneralRe: Extract Data from PDF's Pin
OriginalGriff1-Aug-23 10:50
mvaOriginalGriff1-Aug-23 10:50 
GeneralRe: Extract Data from PDF's Pin
Kevin Marois1-Aug-23 11:42
professionalKevin Marois1-Aug-23 11:42 
GeneralRe: Extract Data from PDF's Pin
OriginalGriff1-Aug-23 12:15
mvaOriginalGriff1-Aug-23 12:15 
GeneralRe: Extract Data from PDF's Pin
Gerry Schmitz1-Aug-23 15:27
mveGerry Schmitz1-Aug-23 15:27 
GeneralRe: Extract Data from PDF's Pin
Pete O'Hanlon1-Aug-23 20:46
subeditorPete O'Hanlon1-Aug-23 20:46 
GeneralRe: Extract Data from PDF's Pin
OriginalGriff1-Aug-23 21:51
mvaOriginalGriff1-Aug-23 21:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.