请问谁电脑里有visual studio C#的软件 可以帮我运行一下这个C#的程序吗?我没有装这个软件。求输出结果!
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceAnimals{classDo...
using System;
using System.Collections.Generic;
using System.Text;
namespace Animals
{
class Dog
{
private string name;
public Dog()
{ name = "unknown"; }
public Dog(string initianame)
{ name = initianame; }
public string Name
{
get { return name; }
}
}
public override string ToString()
{
return "Dog name:"+name;
}
public override bool Equals(object obj)
{
Dog tempDog=(Dog)obj;
if(tempDog.Name==name)
{
return ture;
}
else
{
return false;
}
}
}
}
class ObjectTester
{
public static void Main()
{
Animals.Dog myDog = new Animals.Dog("Fido");
Animals.Dog yourDog = new Animals.Dog("Fido");
Console.WriteLine(myDog);
if (myDog.Equals(yourDog))
Console.WriteLine("myDog has the same name as yourDog");
else
Console.WriteLine("myDog and yourDog have different names");
}
} 展开
using System.Collections.Generic;
using System.Text;
namespace Animals
{
class Dog
{
private string name;
public Dog()
{ name = "unknown"; }
public Dog(string initianame)
{ name = initianame; }
public string Name
{
get { return name; }
}
}
public override string ToString()
{
return "Dog name:"+name;
}
public override bool Equals(object obj)
{
Dog tempDog=(Dog)obj;
if(tempDog.Name==name)
{
return ture;
}
else
{
return false;
}
}
}
}
class ObjectTester
{
public static void Main()
{
Animals.Dog myDog = new Animals.Dog("Fido");
Animals.Dog yourDog = new Animals.Dog("Fido");
Console.WriteLine(myDog);
if (myDog.Equals(yourDog))
Console.WriteLine("myDog has the same name as yourDog");
else
Console.WriteLine("myDog and yourDog have different names");
}
} 展开
3个回答
展开全部
og sameDog //创建对象
错写成
Animals.Dog.sameDog //引用对象
改过来就行了。输出为:
ToString():Animals.Dog
Type:Animals.Dog
mydog and yourdog are referencing different objects
my dog is referencing the same object as samedog
mydog and yourdog are referening different objects
错写成
Animals.Dog.sameDog //引用对象
改过来就行了。输出为:
ToString():Animals.Dog
Type:Animals.Dog
mydog and yourdog are referencing different objects
my dog is referencing the same object as samedog
mydog and yourdog are referening different objects
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Fido
myDog has the same name as yourDog
myDog has the same name as yourDog
追问
这是输出结果吗? 你可以给我截图看看输出结果好吗?
追答
看那个有图的, 我写的不对
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询