Newbeginner与类交互

问题描述:

Hello People



我正在尝试了解这些类在c#中是如何工作的。

我在下面编写了以下代码,我的问题是如何从输出类打印hello。



请参阅下面的代码:









Hello People

I am trying to understand how the classes works in c#.
I have made following code below, my issue is how do I print "hello" from the outputclass.

see code below:




using System;
//NAMESPACE
namespace Lesson
{

    class Program
    {
        public static void Main()
        {

            //Alert my Printstring

        }
    }

    class Outputclass
    {
        string myString;


        public void PrintString()
        {
            Console.WriteLine("Hello!");
        }

        public Outputclass(string inputString)
        {
            myString = inputString;
        }
    }
}









有人能帮帮我吗?



提前谢谢





Could someone help me?

Thank you in advance

using System;
//NAMESPACE
namespace Lesson
{

class Program
{
public static void Main()
{

 Outputclass o=new Outclass();
 o.PrintString();

 Console.Readline(); 
}
}

class Outputclass
{
string myString;


public void PrintString()
{
Console.WriteLine("Hello!");
}

public Outputclass(string inputString)
{
myString = inputString;
}
}
}


你需要



1)实例化/创建一个Outputclass类型的对象 - 在你的'main'中

2)调用你实例化的对象的PrintString()方法(1)



(使用字符串创建Outputclass类型的对象似乎有点无意义,你不使用字符串,但让我们超越第一个障碍)



所以,你怎么做point(1)..提示,查找'new'关键字
you need to

1) instantiate/create an object of type Outputclass - in your 'main'
2) call the PrintString() method of the object you instantiated at (1)

(it seems a bit pointless to be creating the object of type Outputclass with a string, you dont use the string, but lets get past the first hurdle)

so, how do you do point (1) .. hint, lookup the 'new' keyword


创建一个的实例Outputclass 然后调用print方法。
Create an instance of Outputclass and then call the print method.
Outputclass opc = new Outputclass();
opc.PrintString();





您可以在main方法中执行此操作。



You would do this in the main method.