Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding const keyword breaks Path.Combine call

Tags:

c#

.net

No idea why when I change this:

using System;
using System.IO;

    public static class Constants
    {
        public static string  MainCarFilePath = Path.Combine(Environment.CurrentDirectory, "\\Cars.csv");
    }

to this:

using System;
using System.IO;


    public static class Constants
    {
        public const string MainCarFilePath = Path.Combine(Environment.CurrentDirectory, "\\Cars.csv");
    }

That now it breaks and it doesn't recognize the Combine method of the Path object (System.IO).

I get can't resolve Combine...

like image 364
PositiveGuy Avatar asked Sep 12 '26 22:09

PositiveGuy


1 Answers

const requires that the value be constant at compile time.

Use public static readonly string, instead.

like image 161
Jim Mischel Avatar answered Sep 14 '26 11:09

Jim Mischel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!