当前位置:网站首页>Comment imprimer le tableau original
Comment imprimer le tableau original
2022-07-01 06:24:00 【Steve Draw】
Table des matières:
Préface:
Un tableau est une structure de données très importante,On l'utilise souvent,Peut - être que le plus long est de les traverser et de les imprimer,Mais il y a un petit problème qu'on imprime en traversant,Il arrive souvent que la forme ne ressemble pas à la structure originale!
- Prenons par exemple un tableau,La structure du tableau, par exemple:
int [] b= new int []{
1,2,3}
- Prenons l'exemple d'un appel à une fonction d'impression en ligne(Il en va de même pour l'impression à une seule ligne,Juste pour illustrer la situation),Imprimer les entrées comme suit:
1
2
3
.De cette façon, si nous utilisons d'autres structures de tableau en même temps et imprimons àCLIÇa affecte le jugement et la lecture,De cette façon, il semble que nous ayons besoin de revenir à ce que les tableaux ressemblent lorsque le Code est défini!
Solutions
Nous avons besoin d'écrire une fonction d'impression dédiée à la sortie d'un type de tableau spécifique pour la ligne!Easy!Directement au Code!
(1)Méthode fonctionnelle
static void PrintArray(int[] a)//Le type de tableau spécifique peut être modifié en fonction de la réalité
{
//Le tableau d'entrée doit être jugé vide
if (a.Length != 0)
{
string str = "";
foreach (var i in a)
{
str = str + i + ",";
}
WriteLine("[" + str.Substring(0, str.Length - 1) + "]");//AdoptionSubstring() Supprimer les caractères correspondants
}
if (a.Length == 0) WriteLine("[]");//Si le tableau est vide, Il suffit d'imprimer un format de tableau vide
}
Si souvent utilisé, Dans un projet de bibliothèque de classe , Encapsuler les fonctions dans une méthode de classe , Cela optimisera votre efficacité !
(2)Code complet(Code d'essai ci - joint):
using static System.Console;
namespace ConsoleApp1
{
class Program
{
static void PrintArray(int[] a)//Le type de tableau spécifique peut être modifié en fonction de la réalité
{
//Le tableau d'entrée doit être jugé vide
if (a.Length != 0)
{
string str = "";
foreach (var i in a)
{
str = str + i + ",";
}
WriteLine("[" + str.Substring(0, str.Length - 1) + "]");//AdoptionSubstring() Supprimer les caractères correspondants
}
if (a.Length == 0) WriteLine("[]");//Si le tableau est vide, Il suffit d'imprimer un format de tableau vide
}
static void Main(string[] args)
{
int[] a=new int[] {
1,2,3};
PrintArray(a);
ReadKey();
}
}
}
- Les résultats sont les suivants:
[1,2,3]
S'il y a des lacunes dans le texte final , Je vous serais obligé de bien vouloir faire le nécessaire pour corriger !
边栏推荐
- FPGA - clocking -02- clock wiring resources of internal structure of 7 Series FPGA
- [ManageEngine Zhuohao] the role of LAN monitoring
- Solve the problem of garbled files uploaded by Kirin v10
- Factorial divisor (unique decomposition theorem)
- 让厦门灌口镇田头村变“甜头”村的特色农产品之一是
- webapck打包原理--启动过程分析
- Self confidence is indispensable for technology
- C语言课设学生考勤系统(大作业)
- HDU - 1501 zipper (memory deep search)
- 【ManageEngine卓豪】助力黄石爱康医院实现智能批量化网络设备配置管理
猜你喜欢

端口扫描工具对企业有什么帮助?

69 Cesium代码datasource加载geojson

Freeswitch dial the extension number
![Pit of kotlin bit operation (bytes[i] and 0xff error)](/img/2c/de0608c29d8af558f6f8dab4eb7fd8.png)
Pit of kotlin bit operation (bytes[i] and 0xff error)

【KV260】利用XADC生成芯片温度曲线图

Picture server project test

C语言课设学生考勤系统(大作业)

HCM Beginner (II) - information type

Ant new village is one of the special agricultural products that make Tiantou village in Guankou Town, Xiamen become Tiantou village
![[summary of knowledge points] chi square distribution, t distribution, F distribution](/img/a6/bb5cabbfffb0edc9449c4c251354ae.png)
[summary of knowledge points] chi square distribution, t distribution, F distribution
随机推荐
High order binary balanced tree
Save data in browser to local file
C语言课设学生选修课程系统(大作业)
async 与 await
How does the port scanning tool help enterprises?
[self use of advanced mathematics in postgraduate entrance examination] advanced mathematics Chapter 1 thinking map in basic stage
蚂蚁新村田头村变甜头村 让厦门灌口镇田头村变甜头村的特色农产品之一是
The row and column numbers of each pixel of multi-source grid data in the same area are the same, that is, the number of rows and columns are the same, and the pixel size is the same
端口扫描工具是什么?端口扫描工具有什么用
Diffusion (multi-source search)
【ManageEngine】如何实现网络自动化运维
让厦门灌口镇田头村变甜头村的特色农产品之一是蚂蚁新村
DHT11 temperature and humidity sensor
68 Cesium代码datasource加载czml
Redis安装到Windows系统上的详细步骤
How does MySQL store Emoji?
SystemVerilog learning-07-class inheritance and package use
浅谈SIEM
Index method and random forest to realize the information of surface water body in wet season in Shandong Province
Mysql 表分区创建方法