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 >
<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(';');
}
}
}
CodePudding user response:
You have declared lines
inside a method, so it is scoped 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
}
}
}