
正文
vb.netint数组 vb string数组
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
vb.net数组如何赋值
Dim abc(2) As Integer
abc = {0, 1, 2}
'或者
Dim abcd() As Integer
ReDim abcd(9)
For i As Integer = 0 To abcd.Length - 1
abcd(i) = i
Next
也可声明为字符串数组
相关问答
Q1: vb.net中定义一维整型数组语句是
Dim intArray() As Integer
- Or -
Dim intArray() As Integer = New Integer() { 0 }
- Or -
Dim intArray As Integer()
- Or -
Dim intArray As Integer() = New Integer() { 0 }
- Or -
Dim intArray(10) As Integer
Q2: vb.net 如何将字符串转换为integer类型的数据?
1、int类型数组转换为Integer类型的数组。
2、long类型数组转换为Integer类型的数组。
3、char类型数组转换为Integer类型的数组。
4、String类型数组转换为Integer类型的数组。
5、double类型数组转换为Integer类型的数组。
Q3: VB中数组怎么定义
是这么定义的:
数组中的第一个元素的下标称为下界,最后一个元素的下标称为上界,其余的元素连续地分布在上下界之间,且数组在内存中也是用连续的区域来存储的,所以数组每维的长度不能超过Long数据类型的最大值,即264—1=263。
把VB.NET数组当作一个对象来处理,就意味着数组类型是单个引用类型,数组变量包括指向构成数组元素、数组维和数组长度等数据的指针,数组之间互相赋值但仅仅是在相互复制指针,数组继承了System名字空间的Array类。
VB.NET中的数组有两种类型:定长数组和动态数组。
扩展资料:
1、数组的使用
在’VB 6.0中,能够用For Each来循环遍历一个数组。
比如:
Dim x As Integer
F0r Each x In arrayl
Console.WriteLine(x)
Next
2、在VB.NET中能够使用For循环和数组长度来遍历一个数组。
比如:
Dim i As工nteger
F0r i=0 T0 (arrayl.Length-1)
(此处空一行)
Console.WriteLine(arrayl(1)J
Next i
Q4: vb.net 有时候字符串数组可以当整数数组使用
如果不是用冒泡法用这个
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim My_str() As String = {"123", "45", "6", "12"}
Dim my_int() As Integer = System.Array.ConvertAll(My_str, New Converter(Of String, Integer)(AddressOf StrToInt))
System.Array.Sort(my_int)
Dim My_array() As String = Array.ConvertAll(my_int, New Converter(Of Integer, String)(AddressOf IntToStr))
End Sub
Public Shared Function StrToInt(ByVal bs As String)
Return CInt(bs)
End Function
Public Shared Function IntToStr(ByVal bs As Integer)
Return CStr(bs)
End Function
End Class
My_array() 是结果
Q5: vb.net变成 数组组合情况输出问题
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication42
{
class Program
{
static void Main(string[] args)
{
count = 0;
String[] s = Console.ReadLine().Split(' ');
int[] array = new int[s.Length];
for (int i = 0; i s.Length; i++)
{
array[i] = Convert.ToInt32(s[i]);
}
int m = Convert.ToInt32(Console.ReadLine());
Listint arraylist = new Listint();
arraylist.AddRange(array);
Output(arraylist, m, null);
Console.WriteLine("共有" + count.ToString() + "个");
Console.ReadKey();
}
static int count = 0;
static void Output(Listint array, int m, Listint output)
{
if (output == null)
output = new Listint();
if (m == 0)
{
for (int i = 0; i output.Count; i++)
{
Console.Write(output[i].ToString() + " ");
}
Console.Write("\r\n");
count++;
return;
}
else
{
for (int i = 0; i array.Count; i++)
{
Listint output2 = new Listint();
output2.AddRange(output.ToArray());
output.Add(array[i]);
Listint array2 = new Listint();
array2.AddRange(array.ToArray());
for (int j = 0; j = i; j++)
{
int number = array[j];
array2.Remove(number);
}
Output(array2, m - 1, output);
output.Clear();
output.AddRange(output2.ToArray());
}
}
}
}
}
额,没注意VB,用C#写的。。。
输出了的,你新建一个C#控制台程序,把这段贴进去,运行一下就知道了
先输入一组字符串,然后输入一个整数,就会把所有的组合输出出来
我把这段转成VB再发一次吧
Module Module1
Sub Main()
count = 0
Dim s As String() = Console.ReadLine().Split(" ")
Dim array(0 To s.Length - 1) As Integer
For i As Integer = 0 To s.Length - 1
array(i) = Convert.ToInt32(s(i))
Next
Dim m As Integer = Convert.ToInt32(Console.ReadLine())
Dim arraylist As New List(Of Integer)
arraylist.AddRange(array)
Print(arraylist, m, Nothing)
Console.WriteLine("共有" + count.ToString() + "个")
Console.ReadKey()
End Sub
Sub Print(ByRef array As List(Of Integer), ByVal m As Integer, ByRef output As List(Of Integer))
If output Is Nothing Then
output = New List(Of Integer)()
End If
If m = 0 Then
For i As Integer = 0 To output.Count - 1
Console.Write(output(i).ToString() + " ")
Next
Console.Write(vbCrLf)
count = count + 1
Return
Else
For i As Integer = 0 To array.Count - 1
Dim array2 As New List(Of Integer)
Dim output2 As New List(Of Integer)
output2.AddRange(output.ToArray())
output.Add(array(i))
array2.AddRange(array.ToArray())
For j As Integer = 0 To i
Dim number As Integer = array(j)
array2.Remove(number)
Next
Print(array2, m - 1, output)
output.Clear()
output.AddRange(output2.ToArray())
Next
End If
End Sub
Dim count As Integer = 0
End Module
关于vb.netint数组和vb string数组的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






