
正文
vb.net匿名列表 匿名内部类的方法怎么调用
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
VB.NET中匿名方法怎么写,最简单的就可以
public static String reverse1(String str)
{
return new StringBuffer(str).reverse().toString();
}
2.最常用的方法:
public static String reverse3(String s)
{
char[] array = s.toCharArray();
String reverse = ""; //注意这是空串,不是null
for (int i = array.length - 1; i = 0; i--)
reverse += array[i];
return reverse;
}
3.常用方法的变形:
public static String reverse2(String s)
{
int length = s.length();
String reverse = ""; //注意这是空串,不是null
for (int i = 0; i length; i++)
reverse = s.charAt(i) + reverse;//在字符串前面连接, 而非常见的后面
return reverse;
}
4.C语言中常用的方法:
public static String reverse5(String orig)
{
char[] s = orig.toCharArray();
int n = s.length - 1;
int halfLength = n / 2;
for (int i = 0; i = halfLength; i++) {
char temp = s[i];
s[i] = s[n - i];
s[n - i] = temp;
}
return new String(s); //知道 char数组和String相互转化
}
相关问答
Q1: 关于VB.NET的数据列表,懂 VB.NET的高手都来啊~~
给vb.net匿名列表我吧,我就少分vb.net匿名列表了!hi我就行
Q2: c#中的delegate在vb.net中应该怎样表达?
呵呵,我对VB用的不多,搜索了一下,发现下面的语法是有些问题,你可以参考MSDN的示例代码,重新写一遍:
你这使用了匿名函数,貌似VB不支持匿名函数,只能定义函数后再调用
如:
'先定义委托
Public Delegate Sub dele()
Public Sub f1()
方法内容
End Sub
'调用
Dim instance As New dele(AddressOf f1)
button.Clicked += instance
Q3: VB匿名管道执行CMD并回显
方法 1ReDos text1.text,Temptext2.text=Temp '***************读取DOS文本*****************
'* ReDos "Net Share",TempTxt *
'* TempTxt 为返回的文本 *
'* 作者:Christly QQ:105120185 *
'*******************************************Option Explicit
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
lpProcessAttributes As Any, _
lpThreadAttributes As Any, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
lpEnvironment As Any, _
ByVal lpCurrentDriectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As LongPublic Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As LongPrivate Declare Function CreatePipe Lib "kernel32" (phReadPipe As Long, _
phWritePipe As Long, _
lpPipeAttributes As SECURITY_ATTRIBUTES, _
ByVal nSize As Long) As Long
Private Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Byte
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Const NORMAL_PRIORITY_CLASS = H20
Private Const STARTF_USESTDHANDLES = H100
Private Const STARTF_USESHOWWINDOW = H1
Private Const SW_HIDE = 0
Private Const INFINITE = HFFFF ' Infinite timeout
Public Sub UniteByteArray(B1() As Byte, B2() As Byte, ByRef RetB() As Byte) '合并数组
Dim TB() As Byte
Dim LB1 As Integer
Dim LB2 As Integer
Dim i As Integer
LB1 = UBound(B1)
LB2 = UBound(B2)
ReDim TB(0 To LB1 + LB2 + 1) As Byte
For i = 0 To LB1
TB(i) = B1(i)
Next i
For i = LB1 + 1 To UBound(TB)
TB(i) = B2(i - LB1 - 1)
Next i
RetB = TB
' SDBug UBound(TB)
End Sub
Public Sub ReDos(commandline As String, ByRef ReturnTxt As String)
Dim si As STARTUPINFO 'userd to send info the createProcess
Dim pi As PROCESS_INFORMATION 'used to receive info about the created process
Dim retval As Long 'return value
Dim hRead As Long 'the handle to the read end of pipe
Dim hWrite As Long 'the handle to the write end of the pipe
Dim sBuffer(0 To 63) As Byte 'the buffer to store data as we read it from the pipe
Dim lgSize As Long 'returned number of bytes read by readfile
Dim sa As SECURITY_ATTRIBUTES
Dim strResult As String 'returned results of the command line
Dim TB() As Byte, FristT As Boolean
'set up security attributes structure
With sa
.nLength = Len(sa)
.bInheritHandle = 1 'ingerit,needed for this to work
.lpSecurityDescriptor = 0
End With
'create our anonymous pipe an check for success
'note we use the default buffer size
'this could cause problems if the process tries to write more than this buffer size
retval = CreatePipe(hRead, hWrite, sa, 0)
If retval = 0 Then
MsgBox "错误提示:创建管道失败!"
ReturnTxt = ""
Exit Sub
End If
'set up startup info
With si
.cb = Len(si)
.dwFlags = STARTF_USESHOWWINDOW Or STARTF_USESTDHANDLES 'tell it to use(not ignore)the values below
.wShowWindow = SW_HIDE
.hStdOutput = hWrite 'pass the write end of the pipe as the processes standard output
End With
'run the command line and check for success
retval = CreateProcess(vbNullString, commandline vbNullChar, sa, sa, 1, NORMAL_PRIORITY_CLASS, ByVal 0, vbNullString, si, pi)
If retval Then
'wait until the command line finishes
'trouble if the app doesnt end ,or waits for user input,etc
WaitForSingleObject pi.hProcess, H10000 '等待10000毫秒
FristT = True
'read from the pipe until theres no more(bytes actually read if less than what we told it to )
Do
Erase sBuffer()
If ReadFile(hRead, sBuffer(0), 64, lgSize, ByVal 0) Then
SDBug "lgSize=" lgSize
If FristT = True Then
'convert byte array to string and append to our result
TB = sBuffer
FristT = False
Else
UniteByteArray TB, sBuffer, TB
End If
Else
SDBug "fuck"
End If
'todo = whats in the tall end of the byte array when lgSize if less than 64???
If lgSize 64 Then Exit Do
DoEvents
Loop
strResult = strResult StrConv(TB(), vbUnicode)
'close the handles of the process
CloseHandle pi.hProcess
CloseHandle pi.hThread
Else
MsgBox "错误提示:创建进程失败!" vbCrLf
End If
'close pipe handles
CloseHandle hRead
CloseHandle hWrite
'return the command line output
ReturnTxt = Replace(strResult, vbNullChar, "")
End Sub
Q4: vb.net中的list怎样用数组添加列表项
list1.additem j 意思就是把j添加至list1列表中,这是在一个for 循环中,循环了10次,添加了10次 j,即 list1 中 有10列分别为:1,3,6,10,15,21,28,36,45,55
下面又来了一个循环, list1.removeitem 删除列,删除的是 list1.listcount - i ,list1.listcount 就是总列数为10,减去 i ,i 是1到4,即10-1,9-2,8-3,7-4 每减掉一次,list1.listcount 就少了一条记录。
(注意,list1.listcount-1 是最后一条记录)
减掉了第 9,7,5,3列
剩余为 1,3,6,15,28,45
结果为:3,15,28
'ListCount返回列表框中的项目总数
'ListCount-1是列表框中最后一个项目的索引号
'亏你提醒了,我写错了,上面修改了,第一个索引为0,最后一个为9.
'也就是,问题所问的第二列的索引为1,第四列的索引为3...
关于vb.net匿名列表和匿名内部类的方法怎么调用的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






