开发者

Am I going mad? c# / static modifier

I have the below code, oddly enough it keeps on returning the same value (even though filename) is different, if i call it more than once in the same request.

Ive just stepped through the code and even stringbytes is exactly the same (i.e. GetBytes(string)) is returning the same 开发者_如何转开发value.

    public static string Base64EncodeString(string filename)
    {
        var stringbytes = System.Text.Encoding.Default.GetBytes(filename);
        return Convert.ToBase64String(stringbytes);
    }


I suspect you're not seeing what you think you're seeing. That method won't return the same value if you call it with different values of filename... unless you're using characters which aren't supported by Encoding.Default. (I wouldn't suggest using Encoding.Default unless you really want a platform-specific encoding.)


Your code looks correct. If it's not an Encoding issue as suggested by Jon Skeet i would guess that you have a static fileName and/or stringbytes variable somewhere and that the posted code is not 100% the same as the original code.


Did you check the files that you are loading. It is possible that you just copied the file that you are opening, gave it a different name and did not modify the content.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜