2
I’m trying to learn C-language. In this case I’m trying to get the Console to show the balance value by taking this value from a different class in the same file (I’ve tried it with multiple-files and it still doesn’t work, the compiler doesn’t see the variable).
using System;
using namespaceb;
namespace namespaceb
{
public class saldo
{
public int numero = 100;
}
}
namespace namespacea
{
class Program
{
static void Main(string[] args)
{
saldo teste = new saldo();
Console.WriteLine(numero); //dá erro "O nome Numero não existe no contexto atual"
Console.WriteLine(teste); // mostra uma linha "namespaceb.saldo"
Console.ReadKey();
}
}
}
If the class is in the same
namespace
you can use hersaldo s = new saldo();
nexts.numero
– gato
only missing
Console.WriteLine(teste.numero);
– Rovann Linhalis