当我试图通过数组的字段访问时,无法访问字段 "title"
Can't get access to the field "title",when I'm trying to acces via field of a array
当我尝试通过数组字段访问“标题”字段时,无法访问它。所以,伙计们,我正在尝试访问字段标题,例如 ShellContent1_2.Title,而不是像 ShellContent1_2.Title、ShellContent2_2.Title 这样的写法...我正在使用数组和循环为了。
请帮我。谢谢
namespace RakeshProj;
using Microsoft.Extensions.Configuration;
public partial class AppShell: Shell
{
public AppShell()
{
InitializeComponent();
//Extensions.JsonRead(@"C:\Users\Matsenko\source\repos\TestJson\TestJson\appsettings.json");
IConfiguration config = new ConfigurationBuilder()
.AddJsonFile("appsettings`.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
//Menu menu_settings = config.GetSection("ShellContentNames").Get<Menu>();
//CounterLabel.Title = "Hey";
//SemanticScreenReader.Announce(CounterLabel.Title);
string[][] ShellContentNames=
{
new string[3]
{
"ShellContent1_1","ShellContent2_1","ShellContent3_1"
},
new string[12]
{
"ShellContent1_2","ShellContent2_2","ShellContent3_2",
"ShellContent4_2","ShellContent5_2","ShellContent6_2",
"ShellContent7_2","ShellContent8_2","ShellContent9_2",
"ShellContent10_2","ShellContent11_2","ShellContent12_2"
}
};
for (int i = 0; i < ShellContentNames.Length; i++)
{
for(int j=0; j < ShellContentNames[j].Length; j++)
{
ShellContentNames[i][j].Title = "Hey";
SemanticScreenReader.Announce(ShellContentNames[i][j].Title);
}
}
}
}
(为便于阅读而添加的格式):
var page = new ContentPage();
page.Title = "blah";
This works because page
is an instance of the ContentPage
class, and
that class has a property named Title
.
var page = "ContentPage";
This just creates a string with the value ContentPage
. They are completely different things.
在我的例子中,我需要使用 ShellContent
而不是 ContentPage
。
当我尝试通过数组字段访问“标题”字段时,无法访问它。所以,伙计们,我正在尝试访问字段标题,例如 ShellContent1_2.Title,而不是像 ShellContent1_2.Title、ShellContent2_2.Title 这样的写法...我正在使用数组和循环为了。 请帮我。谢谢
namespace RakeshProj;
using Microsoft.Extensions.Configuration;
public partial class AppShell: Shell
{
public AppShell()
{
InitializeComponent();
//Extensions.JsonRead(@"C:\Users\Matsenko\source\repos\TestJson\TestJson\appsettings.json");
IConfiguration config = new ConfigurationBuilder()
.AddJsonFile("appsettings`.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
//Menu menu_settings = config.GetSection("ShellContentNames").Get<Menu>();
//CounterLabel.Title = "Hey";
//SemanticScreenReader.Announce(CounterLabel.Title);
string[][] ShellContentNames=
{
new string[3]
{
"ShellContent1_1","ShellContent2_1","ShellContent3_1"
},
new string[12]
{
"ShellContent1_2","ShellContent2_2","ShellContent3_2",
"ShellContent4_2","ShellContent5_2","ShellContent6_2",
"ShellContent7_2","ShellContent8_2","ShellContent9_2",
"ShellContent10_2","ShellContent11_2","ShellContent12_2"
}
};
for (int i = 0; i < ShellContentNames.Length; i++)
{
for(int j=0; j < ShellContentNames[j].Length; j++)
{
ShellContentNames[i][j].Title = "Hey";
SemanticScreenReader.Announce(ShellContentNames[i][j].Title);
}
}
}
}
var page = new ContentPage(); page.Title = "blah";
This works because
page
is an instance of theContentPage
class, and that class has a property namedTitle
.var page = "ContentPage";
This just creates a string with the value
ContentPage
. They are completely different things.
在我的例子中,我需要使用 ShellContent
而不是 ContentPage
。