Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Blazor CS0103: "The name 'lines' does not exist in the current context

Hello stackoverflow community, I am getting error CS0103 I’ve searched google but couldn’t find an answer sorry if this is a bad question I’m new with Blazor.

I’m Trying to make a table from a comma seperated file.

@page "/fetchdata"


<PageTitle>Keyword analytics</PageTitle>

@using BlazorApp.Data


<h1>Keyword Analytics</h1>

 <table class="table">
        <thead>
            <tr>
                <th>Keyword</th>
                <th>Volume</th>
                <th>Competition</th>
                <th>Results</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var line in lines)
            {
                <tr>
                    <td>@line[0]</td>
                    <td>@line[1]</td>
                    <td>@line[2]</td>
                    <td>@line[3]</td>
                </tr>
            }
        </tbody>
    </table>


@code
{

    protected override void OnInitialized()
    { 
        string[] lines = File.ReadAllLines(@"C:\Users\someone\Desktop\max\BlazorApp\Something.txt");

        foreach (var line in lines)
        {
            line.Split(';');
        }
    }
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You have declared lines inside a method, so it is private to that method.

@code
{
    string[] lines = Array.Empty<string>();

    protected override void OnInitialized()
    { 
        lines = File.ReadAllLines(@"C:\Users\ra1n\Desktop\max\BlazorApp\SemRUSH.txt");

        foreach (var line in lines)
        {
            line.Split(';'); // This does not do anything except waste CPU
        }
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading