开发者

How to define text which won't change in C# - 4.0 - Best performance - 2 Languages support - EXPERT

I am supporting two different languages at my web application. So I have 2 different string for everything. I am asking that what is the best way of defining static texts. I mean are there any performance difference between these 4 four examples or any other better way?

static private string srLang1 = "Username";
private string srLang2 = "Username";
static string srLang3 = "Username";
string srLang4 = "Username";
const string srLang5="Username";
private const string s开发者_JS百科rLang6 = "Username";


I can't see any performance issues associated with the declarations.

Better way to provide different text for different languages would be globalizing your application using Resources.

Globalization Architecture for ASP.NET

Basically you define strings and other localizable items, such as images, in Resources. Then you can reference resources from your source code.


private const string srLang6 = "Username"; seems the best. ReSharper plugin would suggest this way.


I suppose you are looking for Resources Files and Globalization. Search on the internet or look at the links provided in this question.

Although I would not recommend your way of globalizing an application the best choice in terms of performance between your options is const string myString = "hello" (please note that there is no difference between private type varName = something and type varName = something. In C# all members are implicitly private by default unless you specify a modifier)


You definitely should take a look at the MSDN Article series on Globalization and Localization. It shows you how to properly support multiple languages on your site without having to do things like you try above:

ASP.NET Globalization and Localization

Start with all of the articles in the Localizing ASP.NET Web Pages By Using Resources and just keep working your way through.


This older article talks a little about measuring performance on static vs non-static. As for private vs non-private, Everything I know says it shouldn't make a difference, but compilers sometimes do funny things.

The best answer is for you to measure the differences in your program using some sort of performance testing. As much as we can talk about theory, nothing beats cold hard data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜