当前位置:网站首页>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 !
边栏推荐
- idea 好用插件汇总!!!
- 分布式锁实现
- 【ManageEngine卓豪】助力黄石爱康医院实现智能批量化网络设备配置管理
- make: g++:命令未找到
- Discrimination between left and right limits of derivatives and left and right derivatives
- 高阶-二叉搜索树详解
- Highmap gejson data format conversion script
- To sort out the anomaly detection methods, just read this article!
- SystemVerilog learning-10-validation quantification and coverage
- [automatic operation and maintenance] what is the use of the automatic operation and maintenance platform
猜你喜欢

C# ManualResetEvent 类的理解

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
![[automatic operation and maintenance] what is the use of the automatic operation and maintenance platform](/img/14/756d566744d6e4a988a284c5b30130.png)
[automatic operation and maintenance] what is the use of the automatic operation and maintenance platform

Movable mechanical wall clock

虚幻 简单的屏幕雨滴后处理效果

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

Redis安装到Windows系统上的详细步骤
![阿里OSS Postman Invalid according to Policy: Policy Condition failed: [“starts-with“, “$key“, “test/“]](/img/3c/7684b7c594f7871471f89007294703.png)
阿里OSS Postman Invalid according to Policy: Policy Condition failed: [“starts-with“, “$key“, “test/“]

On siem

C语言课设职工信息管理系统(大作业)
随机推荐
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
三分钟带你快速了解网站开发的整个流程
Projects and dependencies in ABP learning solutions
Top 10 Free 3D modeling software for beginners in 2022
kubeadm搭建kubenetes 集群(个人学习版)
[ManageEngine Zhuohao] mobile terminal management solution, helping the digital transformation of Zhongzhou aviation industry
ManageEngine Zhuohao helps you comply with ISO 20000 standard (IV)
Movable mechanical wall clock
【自动化运维】自动化运维平台有什么用
JMM详解
B-树系列
Understanding of C manualresetevent class
高阶-二叉平衡树
1034 Head of a Gang
async 与 await
端口扫描工具是什么?端口扫描工具有什么用
[ManageEngine Zhuohao] the role of LAN monitoring
HCM Beginner (III) - quickly enter pa70 and pa71 to browse employee information PA10
C语言课设工资管理系统(大作业)
How did ManageEngine Zhuohao achieve the goal of being selected into Gartner Magic Quadrant for four consecutive years?