C# constants π

preview_player
Показать описание
C# constants const tutorial example explained

#C# #constants #const

using System;

namespace MyFirstProgram
{
class Program
{
static void Main(string[] args)
{
// constants = immutable values which are known at compile time
// and do not change for the life of the program

const double pi = 3.14;

//pi = 420; //can't change this constant

Console.WriteLine(pi);

Console.ReadKey();
}
}
}
Рекомендации по теме
Комментарии
Автор

using System;

namespace MyFirstProgram
{
class Program
{
static void Main(string[] args)
{
// constants = immutable values which are known at compile time
// and do not change for the life of the program

const double pi = 3.14;

//pi = 420; //can't change this constant

Console.WriteLine(pi);

Console.ReadKey();
}
}
}

BroCodez
Автор

Nice, lets continue watching the course - really good

merdacast
Автор

the best lesson number 4
and the fastest

ibrahemali
Автор

so i wanna use localDB and i have to use a String thats const in my DataBaseHelper,
for some reason it doesnt let me set the
const bd_Path = Directory. GetCurrentDirectory(). Substring (0, Directory. GetCurrentDirectory(). Length-24) + @"Database\Database.mdf;
it seems that it doesnt allow me to define an const with an function :/
is there any way i can bypass that?
i thought about using a global variable and then create that const using the global/public varibale, what do you think?
& thx for the video

ramsay