题如下: using System;
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication4
{
class Program
{
public class Myclass
{
public const int i = 5;
public static readonly string str = "good";
} public class AnotherClass
{
int j = Myclass.i;
string kk = Myclass.str;
} static void Main(string[] args)
{
/* 请问这里要怎么编写才能使结果出现“j = 5 , kk = good”*/
}
}
} 请问该程序中的Main函数要怎么编写??才能使结果出现 j = 5 , kk = good
我出现的问题是编写后总是出错,说是受保护级别限制.
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication4
{
class Program
{
public class Myclass
{
public const int i = 5;
public static readonly string str = "good";
} public class AnotherClass
{
int j = Myclass.i;
string kk = Myclass.str;
} static void Main(string[] args)
{
/* 请问这里要怎么编写才能使结果出现“j = 5 , kk = good”*/
}
}
} 请问该程序中的Main函数要怎么编写??才能使结果出现 j = 5 , kk = good
我出现的问题是编写后总是出错,说是受保护级别限制.
应当将AnotherClass中的i,kk成员设为public的.
public class AnotherClass
{
public int j = Myclass.i;
public string kk = Myclass.str;
} AnotherClass ac = new AnotherClass();
Console.WriteLine("j = {0} ,kk = {1}",ac.j,ac.kk);
可改成
public class AnotherClass
{
public int j = Myclass.i;
public string kk = Myclass.str;
}