Home > database >  Can't get access to the field "title",when I'm trying to acces via field of a ar
Can't get access to the field "title",when I'm trying to acces via field of a ar

Time:05-02

Can't get access to the field "title", when I'm trying to access it via the field of an array. So, guys, I'm trying to get access to the field Title, for instance, ShellContent1_2.Title, instead of writing like ShellContent1_2.Title,ShellContent2_2.Title... I'm using arrays and cycle for. Please help me. Thanks.

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);
            }
        }

    }
}

CodePudding user response:

@Jason wrote in the comments (formatting added for readability):

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.

In my case, I need to use ShellContent instead of ContentPage.

  • Related