Exporter (0) Imprimer
Développer tout

StringBuilder.Append, méthode (Decimal)

Ajoute à la fin de cette instance la représentation sous forme de chaîne d'un nombre décimal spécifié.

Espace de noms : System.Text
Assembly : mscorlib (dans mscorlib.dll)

public StringBuilder Append (
	decimal value
)
public StringBuilder Append (
	Decimal value
)
public function Append (
	value : decimal
) : StringBuilder

Paramètres

value

Valeur à ajouter.

Valeur de retour

Référence à cette instance après l'opération d'ajout.

Type d'exceptionCondition

ArgumentOutOfRangeException

Une augmentation de la valeur de cette instance entraînerait un dépassement de MaxCapacity.

Decimal.ToString permet d'obtenir une représentation sous forme de chaîne de value. La capacité de cette instance est ajustée si nécessaire.

using System;
using System.Text;

class Sample 
{
    public static void Main() 
    {
    string      sep       = ", ";
    string      head      = "<<<";
    char[]      tail      = {'>', '>', '>'};
    char        dash      = '-';
    Object 	obj       = 0;

    bool        xBool     = true;
    byte        xByte     = 1;
    short       xInt16    = 2;
    int         xInt32    = 3;
    long        xInt64    = 4;
    Decimal     xDecimal  = 5;
    float       xSingle   = 6.6F;
    double      xDouble   = 7.7;

// The following types are not CLS-compliant.
    ushort      xUInt16   = 8;
    uint        xUInt32   = 9;
    ulong       xUInt64   = 10;
    sbyte       xSByte    = -11;
//
    StringBuilder sb = new StringBuilder();

    sb = sb.Append(head);                // <<<
    sb = sb.Append(head, 2, 1);          // <<<<
    sb = sb.Append(dash);                // <<<<-
    sb = sb.Append(dash).Append(dash);   // <<<<---

    sb = sb.Append(xBool).Append(sep);
    sb = sb.Append(obj).Append(sep).Append(xByte).Append(sep);
    sb = sb.Append(xInt16);
    sb = sb.Append(sep);
    sb = sb.Append(xInt32);
    sb = sb.Append(sep);
    sb = sb.Append(xInt64);
    sb = sb.Append(sep);
    sb = sb.Append(xDecimal).Append(sep);
    sb = sb.Append(xSingle).Append(sep).Append(xDouble).Append(sep);

// The following Append methods are not CLS-compliant.
    sb = sb.Append(xUInt16).Append(sep);
    sb = sb.Append(xUInt32).Append(sep).Append(xUInt64).Append(sep);
    sb = sb.Append(xSByte);
//
    sb = sb.Append(dash, 3);             // ---
    sb = sb.Append(tail);                // --->>>
    sb = sb.Append(tail, 2, 1);          // --->>>>
   
    String str = sb.ToString();
    Console.WriteLine("The appended string is:");
    Console.WriteLine(str);
    }
}
/*
This example produces the following results:
The appended string is:
<<<<---True, 0, 1, 2, 3, 4, 5, 6.6, 7.7, 8, 9, 10, -11--->>>>
*/

// This example demonstrates StringBuilder.Append()
import System.*;
import System.Text.*;

class Sample
{
    public static void main(String[] args)
    {
        String sep = ", ";
        String head = "<<<";
        char tail[] =  { '>', '>', '>' };
        char dash = '-';
        Object obj = new Integer(0);

        boolean xBool = true;
        ubyte xByte = 1;
        short xInt16 = 2;
        int xInt32 = 3;
        long xInt64 = 4;
        Decimal xDecimal = new Decimal(5);
        float xSingle = 6.6f;
        double xDouble = 7.7;
        // The following types are not CLS-compliant.
        int xUInt16 = 8;
        int xUInt32 = 9;
        long xUInt64 = 10;
        byte xSByte = -11;
        //
        StringBuilder sb = new StringBuilder();

        sb = sb.Append(head); // <<<
        sb = sb.Append(head, 2, 1); // <<<<
        sb = sb.Append(dash); // <<<<-
        sb = sb.Append(dash).Append(dash); // <<<<---
        sb = sb.Append(xBool).Append(sep);
        sb = sb.Append(obj).Append(sep).Append(xByte).Append(sep);
        sb = sb.Append(xInt16);
        sb = sb.Append(sep);
        sb = sb.Append(xInt32);
        sb = sb.Append(sep);
        sb = sb.Append(xInt64);
        sb = sb.Append(sep);
        sb = sb.Append(xDecimal).Append(sep);
        sb = sb.Append(xSingle).Append(sep).Append(xDouble).Append(sep);
        // The following Append methods are not CLS-compliant.
        sb = sb.Append(xUInt16).Append(sep);
        sb = sb.Append(xUInt32).Append(sep).Append(xUInt64).Append(sep);
        sb = sb.Append(xSByte);
        //
        sb = sb.Append(dash, 3); // ---
        sb = sb.Append(tail); // --->>>
        sb = sb.Append(tail, 2, 1); // --->>>>
        String str = sb.ToString();
        Console.WriteLine("The appended string is:");
        Console.WriteLine(str);
    } //main
} //Sample
/*
This example produces the following results:
The appended string is:
<<<<---True, 0, 1, 2, 3, 4, 5, 6.6, 7.7, 8, 9, 10, -11--->>>>
*/

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition

Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.

.NET Framework

Prise en charge dans : 2.0, 1.1, 1.0

Ajouts de la communauté

AJOUTER
Afficher:
© 2015 Microsoft