error CS0103

vibi

New member
Joined
Apr 8, 2021
Messages
2
Programming Experience
Beginner
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

class Program
{
static void Main(string[] args)
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
//LEGGO NOME FILE DA PROCESSARE DALLA LINEA DI COMANDO
var input_file = "trial.dat";
int NYEARS = 32; //30
int NRUNS = 54; //54

//DICHIARO I RANGE DELLE VARIABILI INDIPENDENTI
var bus_types = new[] { "40ftdiesel", "60ftdiesel", "40ftcng", "60ftcng", "40fthybrid", "60fthybrid", "40ft250kWh", "40ft350kWh", "60ft650kWh", "40ft250kWhplugin", "40ft110kWhpantograph", "40ft110kWhwireless" };
var age_types = Enumerable.Range(0, 16).Select(x => x.ToString()).ToArray();
var year_types = Enumerable.Range(1, NYEARS).Select(x => x.ToString()).ToArray();
var run_types = Enumerable.Range(1, NRUNS).Select(x => x.ToString()).ToArray();
//PREPARO LA LISTA CHE CONTERRA LE RIGHE DELL'OUTPUT
List<string> all_output_lines = new List<string>();
//LEGGO IL FILE
var all_input_lines = System.IO.File.ReadAllLines(input_file);
for (int l = 0; l < all_input_lines.Length; l++)
{
var input_line = all_input_lines[l];
//SE NON TROVO IL MARKER PASSO ALLA RIGA SUCCESSIVA
if (!input_line.StartsWith("#MACRO "))
{
//COPIO LA RIGA DIRETTAMENTE SULL'OUTPUT
all_output_lines.Add(input_line);
//CONTINUE MI FA COMINCIARE L'ITERAZIONE SUCCESSIVA SENZA FINIRE QUELLA CORRENTE
continue;
}
if (input_line.StartsWith("#MACRO TABLE maintenance"))
{
//>> command = "maintenance.csv" ("40ft250kWh","40ft350kWh","60ft650kWh","40ft250kWhplugin") %columns% %invariant% %rows%
//PER LA TABELLA DI MAINENANCE HO NTABELLE PER IL TIPO DI BUS, RIGHE PER LA CORSA E COL X ETA'
var maintenance_lines = System.IO.File.ReadAllLines("mcosts.csv");

//LEGGO LE 4 TABELLE (ogni tabella è di tipo double[,], l'array è double[][,])
var kind_subtables = new double[bus_types.Length][,];
//Spezziamo il file in N tabelle che iniziano dalla riga in cui trovo il nome del Kind di autobus
for (int ki = 0; ki < bus_types.Length; ki++)
{
kind_subtables[ki] = new double[run_types.Length, age_types.Length];
var row_name = bus_types[ki];
var relevant_lines = maintenance_lines //DI TUTTE LE RIGHE LETTE DA MAINTENANCE.CSV
.SkipWhile(line => !line.Contains(row_name)) //SALTA TUTTE QUELLE CHE NN CONTENGONO IL NOME DEL TIPO DI BUS
.Skip(3) //SALTANE ALTRE 3 (NUMERO MAGICO)
.Take(run_types.Length) //PRENDINE N DOVE N è IL NUMERO DI CORSE DA CONSIDERARE
.ToArray(); //TRASFORMA IN ARRAY
for (int ri = 0; ri < run_types.Length; ri++) //PER OGNI RIGA RILEVANTE
{
var cells = relevant_lines[ri]
.Split(';') //LA DIVIDO USANDO IL CARATTERE ","
.Skip(1) //SALTO IL PRIMO
.ToArray(); AT THIS POINT I GOT THE ERROR (IN DEBUG)
Document
NomeValoreTipo
age_types[ai]error CS0103: Il nome 'ai' non esiste nel contesto corrente
C#:
for (int ai = 0; ai < age_types.Length; ai++)
{
double parsed = 0;
if (cells[ai] == "-")
parsed = 0;
else if (!double.TryParse(cells[ai], out parsed))
throw new InvalidOperationException($"NON SONO RIUSCITO A TRASFORMARE IL TESTO {cells[ai]} IN NUMERO");

kind_subtables[ki][ri, ai] = parsed;

}
}
}
....
CAN YOU HELP ME?
 
Last edited by a moderator:

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
3,386
Location
Chesapeake, VA
Programming Experience
10+
As great as it is that you are explaining each line of code with comments to try to help us understand the problem -- I wish more posters here would do the same, unfortunately, this is an English language forum. We don't understand most of the explanations that you had written down.

Can you post the code again (in code tags) with an English translation?
 
Joined
Apr 10, 2021
Messages
5
Programming Experience
10+
I don't get this, are you seeing a compilation error or an error during debugging?

If its debugging is there a stack trace? can you include the file "trial.dat" so we can repro the problem?

Also the code as posted won't compile, seems we need both panes of code you posted and an additional four '}' characters.
 
Last edited by a moderator:

Similar threads

Top Bottom