问题
I have this line of code:
strKey &= Strings.StrDup(intKeySize - intLength, chrKeyFill)
What is the equivalent of this code in C#? I can't seem to find it.
回答1:
strKey += new String(chrKeyFill, intKeySize - intLength);
or
strKey = strKey.PadRight(intKeySize, chrKeyFill)
回答2:
strKey += strKey.PadRight(strKey.Length + (intKeySize - intLength), chrKeyFill)
回答3:
Personally I think the String constructor approach is clumsy and less readable than the VB.Net Strings library.
using Microsoft.VisualBasic;
...
Strings.StrDup(2, '\t');
来源:https://stackoverflow.com/questions/5902246/vb-net-convert-strdup-to-c-net