저는 현재 다양한 리소스를 통해 C# OOP을 배우려고합니다. 나는 아직 그것에 대해 아무 것도 배우지 않았지만 나는 객체 대 객체 상호 작용에 대해 생각해 봤다. 불행하게도 그것은 계획에 가지 않았고, 내가 참조해야했던 어떤 물건에 대해 약간 혼란스러워했다. 나는 객체와 객체의 상호 작용을 근본적으로 이해하기 위해 다른 객체의 건강을 감소시키는 간단한 공격 방법을 만들고 싶었다. 코드는 다음과 같습니다.기본 C# 개체 대 개체 상호 작용
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
Dog milo = new Dog("Sparky");
Dog ruffles = new Dog("Ruffles");
milo.Attack(ruffles);
Console.ReadLine();
}
}
class Dog
{
public string name { get; set; }
public int health = 100;
public Dog(string theName)
{
name = theName;
public void Attack(Dog theDog)
{
Console.WriteLine("{0} attacks {1}.", this.name, theDog);
LoseHealth(theDog);
}
public void LoseHealth()
{
Console.WriteLine("{0} loses health!", theDog);
theDog -= 5;
}
}
}
}
코드가 전혀 작동하지 않습니다. 내가 뭘 잘못했는지 생각해? 어떤 도움을 주셔서 감사합니다.
문제가 무엇입니까? – SLaks
작동하지 않습니다. – user2925800
** ** 작동하지 않는 방법은 무엇입니까? 폭발 하는가? – SLaks