'string does not contain a definition for valueOf
Hello I have a Problem With my Code
string does not contain a definition for valueOf
Code In c#
{
public static String e(String str, int i5)
{
return String.valueOf(str.ToCharArray()[(int)(str.Length / i5)]);
}
}
Code In VB.NET
Public Shared Function e(ByVal str As String, ByVal i5 As Integer) As String
Return String.valueOf(str.ToCharArray()(CInt((str.Length / i5))))
End Function
Here IS the Problem String.valueOf
Solution 1:[1]
is what you are expecting is to convert vb to c#?
void Main()
{
string s ="xhhxzx";
int i5 = 3;
string res = e(s, i5);
Console.WriteLine(res);
}
public static String e(String str, int i5)
{
return (str.Length / i5).ToString();
}
you can do in one line
public static String e(String str, int i5) => (str.Length / i5).ToString();
Solution 2:[2]
In Java, valueOf
provides a string representation of some other kind of argument, like a bool true
would become a string "true"
. This code pulls a char out of the string at position Length/i5
, converts it to a string and returns it
In C# you could do that with:
public static String E(string str, int i5)
{
return str[str.Length/i5].ToString();
}
Or:
public static String E(string str, int i5) =>
str[str.Length/i5].ToString();
In VB:
Public Shared Function E(str as String, i5 as Integer) As String
Return str(str.Length/i5).ToString()
End Function
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Caius Jard |