Resource (.resx) file Key naming conventions?

后端 未结 5 432
一生所求
一生所求 2020-12-30 21:13

I\'m building a C# app that will likely contain a couple resource files to store strings for use in language translation. I\'m trying to come up with a naming convention for

5条回答
  •  再見小時候
    2020-12-30 21:24

    If you have a Name Value Pair in resources like

    CloseConfirmation - Do you want to close the window without saving ?

    Add a new class called Messages.

     public static class Messages
    {
        public const String CloseConfirmation = "CloseConfirmation";
        public static String GetMessage( String messageId )
        {
            return //your namespace//.Properties.Resources.ResourceManager.GetString( messageId );
        }}
    

    and to access it use

    MessageBox.Show( Messages.GetMessage(Messages.CloseConfirmation));
    

    Hope this will help.

提交回复
热议问题