VB string function equivalent in c#...

How do i convert this vb code into c#

strTemp = String(255, Chr$(0))
ube100Asked:
Who is Participating?
 
abelCommented:
You don't need API functions old style anymore in .NET. You can use the .NET library functions, which are type safe. In this case:

System.IO.Path.GetTempPath()

If you do not want the "System.IO" in front of it, you can put that in the using headers:

using System.IO;

...
string strTemp = Path.GetTempPath();

As you can see, you do not need to initialize your variables with nullpadded strings anymore. Quite handy this way, isn't it? And whether you use VB.NET or C#.NET or any other .NET language, you can always use these base libraries.
0
 
abelCommented:
Like this:

string strTemp = new string('\0', 255);
0
 
abelCommented:
The '\0' part is the equivalent of the the Chr(0) function (ascii character NUL).

Btw, I assume you meant this as VB code, because the mentioned VB code will not compile (first parameter of constructor cannot be an Integer):

Dim strTemp As New String(Chr(0), 255)
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
ube100Author Commented:
next code is:

lRet = GetTempPath(255, strTemp)

API function for the GetTempPath is declared like this:

Private Declare Function GetTempPath Lib "Kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

How will I convert this into C#.
0
 
ube100Author Commented:
thank very much sir for help!!!
0
 
abelCommented:
You're welcome, glad it helped :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.