简体   繁体   中英

Placing strings shared by two or more projects in a referenced project in a solution

I currently have two projects in a solution that share similar classes. In order to resolve the sharing issue of the classes I have created a third project in the solution and both the projects reference those classes. Now I have come to a point where both the projects would need to share common strings. Now I wanted to add those string to the common solution but I am not sure how to approach this. Should I simply create a class and have those strings declared as static with getters and setters ? Any suggestions

You could use constants:

public static class Constants
{
    public const string Message1 = "Foo bar";
    public const string Message2 = "Baz";
}

and then call those constants in the consuming code:

string text = Constants.Message1;

Alternatively you might consider using resource files. The advantage of resource files is that they could be localized in various languages if you need to support multi language application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM