String.Concat Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Aşırı Yüklemeler
| Name | Description |
|---|---|
| Concat(String, String, String, String) |
Belirtilen dört örneğini Stringbirleştirir. |
| Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>) |
Belirtilen dört salt okunur karakter aralığının dize gösterimlerini birleştirir. |
| Concat(Object, Object, Object, Object) |
Belirtilen dört nesnenin ve isteğe bağlı değişken uzunluğu parametre listesinde belirtilen nesnelerin dize gösterimlerini birleştirir. |
| Concat(String, String, String) |
Belirtilen üç örneğini Stringbirleştirir. |
| Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>) |
Belirtilen üç salt okunur karakter aralığının dize gösterimlerini birleştirir. |
| Concat(Object, Object, Object) |
Belirtilen üç nesnenin dize gösterimlerini birleştirir. |
| Concat(String, String) |
belirtilen iki örneğini Stringbirleştirir. |
| Concat(ReadOnlySpan<Object>) |
Belirtilen nesne aralığındaki öğelerin dize gösterimlerini birleştirir. |
| Concat(Object, Object) |
Belirtilen iki nesnenin dize gösterimlerini birleştirir. |
| Concat(String[]) |
Belirtilen String dizinin öğelerini birleştirir. |
| Concat(ReadOnlySpan<String>) |
belirtilen bir aralığının Stringöğelerini birleştirir. |
| Concat(Object[]) |
Belirtilen Object dizideki öğelerin dize gösterimlerini birleştirir. |
| Concat(Object) |
Belirtilen nesnenin dize gösterimini oluşturur. |
| Concat(IEnumerable<String>) |
türündeki Stringbir derlenmiş IEnumerable<T> koleksiyonun üyelerini birleştirir. |
| Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>) |
Belirtilen iki salt okunur karakter aralığının dize gösterimlerini birleştirir. |
| Concat<T>(IEnumerable<T>) |
Bir uygulamanın üyelerini birleştirir IEnumerable<T> . |
Açıklamalar
Not
Dizeleri birleştirmek için dilinizin C# ve F# gibi dize birleştirme işlecini + veya &+ Visual Basic'te de kullanabilirsiniz. Her iki derleyici de birleştirme işlecini aşırı yüklemelerinden String.Concatbirine yapılan bir çağrıya çevirir.
Concat(String, String, String, String)
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
Belirtilen dört örneğini Stringbirleştirir.
public:
static System::String ^ Concat(System::String ^ str0, System::String ^ str1, System::String ^ str2, System::String ^ str3);
public static string Concat(string str0, string str1, string str2, string str3);
public static string Concat(string? str0, string? str1, string? str2, string? str3);
static member Concat : string * string * string * string -> string
Public Shared Function Concat (str0 As String, str1 As String, str2 As String, str3 As String) As String
Parametreler
- str0
- String
Birleştirilmeye ilk dize.
- str1
- String
Birleştirilme ikinci dize.
- str2
- String
Birleştirilme üçüncü dize.
- str3
- String
Birleştirilme dördüncü dize.
Döndürülenler
, , str1str2ve str3birleştirmesistr0.
Örnekler
Aşağıdaki örnek, dört harfli sözcüklerden oluşan bir dizi tanımlar ve bunları karıştırmak için tek tek harflerini bir dize dizisine depolar. Ardından karışık sözcükleri yeniden bir araya getirmek için yöntemini çağırır Concat(String, String, String, String) .
using System;
using System.Collections;
public class Example
{
public static void Main()
{
const int WORD_SIZE = 4;
// Define some 4-letter words to be scrambled.
string[] words = { "home", "food", "game", "rest" };
// Define two arrays equal to the number of letters in each word.
double[] keys = new double[WORD_SIZE];
string[] letters = new string[WORD_SIZE];
// Initialize the random number generator.
Random rnd = new Random();
// Scramble each word.
foreach (string word in words)
{
for (int ctr = 0; ctr < word.Length; ctr++)
{
// Populate the array of keys with random numbers.
keys[ctr] = rnd.NextDouble();
// Assign a letter to the array of letters.
letters[ctr] = word[ctr].ToString();
}
// Sort the array.
Array.Sort(keys, letters, 0, WORD_SIZE, Comparer.Default);
// Display the scrambled word.
string scrambledWord = String.Concat(letters[0], letters[1],
letters[2], letters[3]);
Console.WriteLine("{0} --> {1}", word, scrambledWord);
}
}
}
// The example displays output like the following:
// home --> mheo
// food --> oodf
// game --> aemg
// rest --> trse
open System
open System.Collections
let WORD_SIZE = 4
// Define some 4-letter words to be scrambled.
let words = [| "home"; "food"; "game"; "rest" |]
// Define two arrays equal to the number of letters in each word.
let keys = Array.zeroCreate<float> WORD_SIZE
let letters = Array.zeroCreate<string> WORD_SIZE
// Initialize the random number generator.
let rnd = Random()
// Scramble each word.
for word in words do
for i = 0 to word.Length - 1 do
// Populate the array of keys with random numbers.
keys[i] <- rnd.NextDouble()
// Assign a letter to the array of letters.
letters[i] <- string word[i]
// Sort the array.
Array.Sort(keys, letters, 0, WORD_SIZE, Comparer.Default)
// Display the scrambled word.
let scrambledWord = String.Concat(letters[0], letters[1], letters[2], letters[3])
printfn $"{word} --> {scrambledWord}"
// The example displays output like the following:
// home --> mheo
// food --> oodf
// game --> aemg
// rest --> trse
Imports System.Collections
Module Example
Public Sub Main()
Const WORD_SIZE As Integer = 4
' Define some 4-letter words to be scrambled.
Dim words() As String = { "home", "food", "game", "rest" }
' Define two arrays equal to the number of letters in each word.
Dim keys(WORD_SIZE) As Double
Dim letters(WORD_SIZE) As String
' Initialize the random number generator.
Dim rnd As New Random()
' Scramble each word.
For Each word As String In words
For ctr As Integer = 0 To word.Length - 1
' Populate the array of keys with random numbers.
keys(ctr) = rnd.NextDouble()
' Assign a letter to the array of letters.
letters(ctr) = word.Chars(ctr)
Next
' Sort the array.
Array.Sort(keys, letters, 0, WORD_SIZE, Comparer.Default)
' Display the scrambled word.
Dim scrambledWord As String = String.Concat(letters(0), letters(1), _
letters(2), letters(3))
Console.WriteLine("{0} --> {1}", word, scrambledWord)
Next
End Sub
End Module
' The example displays output like the following:
' home --> mheo
' food --> oodf
' game --> aemg
' rest --> trse
Açıklamalar
yöntemi , , str1str2ve str3öğelerini birleştirirstr0; sınırlayıcı eklemez.
Ayrıca bkz.
Şunlara uygulanır
Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>)
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
Belirtilen dört salt okunur karakter aralığının dize gösterimlerini birleştirir.
public:
static System::String ^ Concat(ReadOnlySpan<char> str0, ReadOnlySpan<char> str1, ReadOnlySpan<char> str2, ReadOnlySpan<char> str3);
public static string Concat(ReadOnlySpan<char> str0, ReadOnlySpan<char> str1, ReadOnlySpan<char> str2, ReadOnlySpan<char> str3);
static member Concat : ReadOnlySpan<char> * ReadOnlySpan<char> * ReadOnlySpan<char> * ReadOnlySpan<char> -> string
Public Shared Function Concat (str0 As ReadOnlySpan(Of Char), str1 As ReadOnlySpan(Of Char), str2 As ReadOnlySpan(Of Char), str3 As ReadOnlySpan(Of Char)) As String
Parametreler
- str0
- ReadOnlySpan<Char>
Birleştirmek için ilk salt okunur karakter aralığı.
- str1
- ReadOnlySpan<Char>
Birleştirmek için ikinci salt okunur karakter aralığı.
- str2
- ReadOnlySpan<Char>
Birleştirmek için üçüncü salt okunur karakter aralığı.
- str3
- ReadOnlySpan<Char>
Birleştirmek için dördüncü salt okunur karakter aralığı.
Döndürülenler
, str1str2 ve str3değerlerinin birleştirilmiş dize gösterimleristr0.
Şunlara uygulanır
Concat(Object, Object, Object, Object)
Önemli
Bu API, CLS uyumlu değildir.
Belirtilen dört nesnenin ve isteğe bağlı değişken uzunluğu parametre listesinde belirtilen nesnelerin dize gösterimlerini birleştirir.
public:
static System::String ^ Concat(System::Object ^ arg0, System::Object ^ arg1, System::Object ^ arg2, System::Object ^ arg3);
[System.CLSCompliant(false)]
public static string Concat(object arg0, object arg1, object arg2, object arg3);
[<System.CLSCompliant(false)>]
static member Concat : obj * obj * obj * obj -> string
Public Shared Function Concat (arg0 As Object, arg1 As Object, arg2 As Object, arg3 As Object) As String
Parametreler
- arg0
- Object
Birleşecek ilk nesne.
- arg1
- Object
Birleşecek ikinci nesne.
- arg2
- Object
Birleşecek üçüncü nesne.
- arg3
- Object
Birleşecek dördüncü nesne.
Döndürülenler
Parametre listesindeki her değerin birleştirilmiş dize gösterimi.
- Öznitelikler
Örnekler
Aşağıdaki örnekte, değişken parametrelerin listesini birleştirmek için yönteminin kullanımı Concat(Object, Object, Object, Object) gösterilmektedir. Bu durumda yöntemi dokuz parametreyle çağrılır.
using System;
using System.Collections;
public class Example
{
public static void Main()
{
const int WORD_SIZE = 4;
// Define some 4-letter words to be scrambled.
string[] words = { "home", "food", "game", "rest" };
// Define two arrays equal to the number of letters in each word.
double[] keys = new double[WORD_SIZE];
string[] letters = new string[WORD_SIZE];
// Initialize the random number generator.
Random rnd = new Random();
// Scramble each word.
foreach (string word in words)
{
for (int ctr = 0; ctr < word.Length; ctr++)
{
// Populate the array of keys with random numbers.
keys[ctr] = rnd.NextDouble();
// Assign a letter to the array of letters.
letters[ctr] = word[ctr].ToString();
}
// Sort the array.
Array.Sort(keys, letters, 0, WORD_SIZE, Comparer.Default);
// Display the scrambled word.
string scrambledWord = String.Concat(letters[0], letters[1],
letters[2], letters[3]);
Console.WriteLine("{0} --> {1}", word, scrambledWord);
}
}
}
// The example displays output like the following:
// home --> mheo
// food --> oodf
// game --> aemg
// rest --> trse
open System
open System.Collections
let WORD_SIZE = 4
// Define some 4-letter words to be scrambled.
let words = [| "home"; "food"; "game"; "rest" |]
// Define two arrays equal to the number of letters in each word.
let keys = Array.zeroCreate<float> WORD_SIZE
let letters = Array.zeroCreate<string> WORD_SIZE
// Initialize the random number generator.
let rnd = Random()
// Scramble each word.
for word in words do
for i = 0 to word.Length - 1 do
// Populate the array of keys with random numbers.
keys[i] <- rnd.NextDouble()
// Assign a letter to the array of letters.
letters[i] <- string word[i]
// Sort the array.
Array.Sort(keys, letters, 0, WORD_SIZE, Comparer.Default)
// Display the scrambled word.
let scrambledWord = String.Concat(letters[0], letters[1], letters[2], letters[3])
printfn $"{word} --> {scrambledWord}"
// The example displays output like the following:
// home --> mheo
// food --> oodf
// game --> aemg
// rest --> trse
Imports System.Collections
Module Example
Public Sub Main()
Const WORD_SIZE As Integer = 4
' Define some 4-letter words to be scrambled.
Dim words() As String = { "home", "food", "game", "rest" }
' Define two arrays equal to the number of letters in each word.
Dim keys(WORD_SIZE) As Double
Dim letters(WORD_SIZE) As String
' Initialize the random number generator.
Dim rnd As New Random()
' Scramble each word.
For Each word As String In words
For ctr As Integer = 0 To word.Length - 1
' Populate the array of keys with random numbers.
keys(ctr) = rnd.NextDouble()
' Assign a letter to the array of letters.
letters(ctr) = word.Chars(ctr)
Next
' Sort the array.
Array.Sort(keys, letters, 0, WORD_SIZE, Comparer.Default)
' Display the scrambled word.
Dim scrambledWord As String = String.Concat(letters(0), letters(1), _
letters(2), letters(3))
Console.WriteLine("{0} --> {1}", word, scrambledWord)
Next
End Sub
End Module
' The example displays output like the following:
' home --> mheo
' food --> oodf
' game --> aemg
' rest --> trse
Açıklamalar
Not
Bu API CLS uyumlu değil. CLS uyumlu alternatif: String.Concat(Object[]). C# ve Visual Basic derleyicileri bu yönteme yapılan çağrıyı çağrısı olarak otomatik olarak String.Concat(Object[])çözümler.
yöntemi parametresiz ToString yöntemini çağırarak parametre listesindeki her nesneyi birleştirir; sınırlayıcı eklemez.
String.Empty herhangi bir null bağımsız değişkeninin yerine kullanılır.
Not
yönteminin Concat son parametresi, birleştirmek için bir veya daha fazla ek nesnenin isteğe bağlı virgülle ayrılmış listesidir.
Arayanlara Notlar
Bu yöntem anahtar sözcüğüyle vararg işaretlenir; başka bir deyişle değişken sayıda parametreyi destekler. Yöntemi Visual C++'tan çağrılabilir, ancak C# veya Visual Basic kodundan çağrılamaz. C# ve Visual Basic derleyicileri çağrılarını Concat(Object, Object, Object, Object) çağrısı olarak Concat(Object[])çözümler.
Şunlara uygulanır
Concat(String, String, String)
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
Belirtilen üç örneğini Stringbirleştirir.
public:
static System::String ^ Concat(System::String ^ str0, System::String ^ str1, System::String ^ str2);
public static string Concat(string str0, string str1, string str2);
public static string Concat(string? str0, string? str1, string? str2);
static member Concat : string * string * string -> string
Public Shared Function Concat (str0 As String, str1 As String, str2 As String) As String
Parametreler
- str0
- String
Birleştirilmeye ilk dize.
- str1
- String
Birleştirilme ikinci dize.
- str2
- String
Birleştirilme üçüncü dize.
Döndürülenler
, str1ve str2birleştirmesistr0.
Örnekler
Aşağıdaki örnek üç dizeyi Concat birleştirmek için yöntemini kullanır ve sonucu görüntüler.
using System;
public class Example
{
public static void Main()
{
String s1 = "We went to a bookstore, ";
String s2 = "a movie, ";
String s3 = "and a restaurant.";
var s = String.Concat(s1, s2, s3);
Console.WriteLine(s);
}
}
// The example displays the following output:
// We went to a bookstore, a movie, and a restaurant.
open System
let s1 = "We went to a bookstore, "
let s2 = "a movie, "
let s3 = "and a restaurant."
String.Concat(s1, s2, s3)
|> printfn "%s"
// The example displays the following output:
// We went to a bookstore, a movie, and a restaurant.
Public Module Example
Public Sub Main()
Dim s1 As String = "We went to a bookstore, "
Dim s2 As String = "a movie, "
Dim s3 As String = "and a restaurant."
Dim s = String.Concat(s1, s2, s3)
Console.WriteLine(s)
End Sub
End Module
' The example displays the following output:
' We went to a bookstore, a movie, and a restaurant.
Açıklamalar
yöntemi , str1ve str2öğelerini birleştirirstr0; sınırlayıcı eklemez.
Ayrıca bkz.
Şunlara uygulanır
Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>, ReadOnlySpan<Char>)
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
Belirtilen üç salt okunur karakter aralığının dize gösterimlerini birleştirir.
public:
static System::String ^ Concat(ReadOnlySpan<char> str0, ReadOnlySpan<char> str1, ReadOnlySpan<char> str2);
public static string Concat(ReadOnlySpan<char> str0, ReadOnlySpan<char> str1, ReadOnlySpan<char> str2);
static member Concat : ReadOnlySpan<char> * ReadOnlySpan<char> * ReadOnlySpan<char> -> string
Public Shared Function Concat (str0 As ReadOnlySpan(Of Char), str1 As ReadOnlySpan(Of Char), str2 As ReadOnlySpan(Of Char)) As String
Parametreler
- str0
- ReadOnlySpan<Char>
Birleştirmek için ilk salt okunur karakter aralığı.
- str1
- ReadOnlySpan<Char>
Birleştirmek için ikinci salt okunur karakter aralığı.
- str2
- ReadOnlySpan<Char>
Birleştirmek için üçüncü salt okunur karakter aralığı.
Döndürülenler
ve str2değerlerinin birleştirilmiş dize gösterimleri.str0str1
Şunlara uygulanır
Concat(Object, Object, Object)
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
Belirtilen üç nesnenin dize gösterimlerini birleştirir.
public:
static System::String ^ Concat(System::Object ^ arg0, System::Object ^ arg1, System::Object ^ arg2);
public static string Concat(object arg0, object arg1, object arg2);
public static string Concat(object? arg0, object? arg1, object? arg2);
static member Concat : obj * obj * obj -> string
Public Shared Function Concat (arg0 As Object, arg1 As Object, arg2 As Object) As String
Parametreler
- arg0
- Object
Birleşecek ilk nesne.
- arg1
- Object
Birleşecek ikinci nesne.
- arg2
- Object
Birleşecek üçüncü nesne.
Döndürülenler
, arg1ve arg2değerlerinin birleştirilmiş dize gösterimleriarg0.
Örnekler
Aşağıdaki örnekte yöntemi gösterilmektedir Concat .
using System;
class stringConcat5 {
public static void Main() {
int i = -123;
Object o = i;
Object[] objs = new Object[] {-123, -456, -789};
Console.WriteLine("Concatenate 1, 2, and 3 objects:");
Console.WriteLine("1) {0}", String.Concat(o));
Console.WriteLine("2) {0}", String.Concat(o, o));
Console.WriteLine("3) {0}", String.Concat(o, o, o));
Console.WriteLine("\nConcatenate 4 objects and a variable length parameter list:");
Console.WriteLine("4) {0}", String.Concat(o, o, o, o));
Console.WriteLine("5) {0}", String.Concat(o, o, o, o, o));
Console.WriteLine("\nConcatenate a 3-element object array:");
Console.WriteLine("6) {0}", String.Concat(objs));
}
}
// The example displays the following output:
// Concatenate 1, 2, and 3 objects:
// 1) -123
// 2) -123-123
// 3) -123-123-123
//
// Concatenate 4 objects and a variable length parameter list:
// 4) -123-123-123-123
// 5) -123-123-123-123-123
//
// Concatenate a 3-element object array:
// 6) -123-456-789
open System
let i = -123
let o: obj = i
let objs: obj[] = [| -123; -456; -789 |]
printfn "Concatenate 1, 2, and 3 objects:"
printfn $"1) {String.Concat o}"
printfn $"2) {String.Concat(o, o)}"
printfn $"3) {String.Concat(o, o, o)}"
printfn "\nConcatenate 4 objects and a variable length parameter list:"
printfn $"4) {String.Concat(o, o, o, o)}"
printfn $"5) {String.Concat(o, o, o, o, o)}"
printfn "\nConcatenate a 3-element object array:"
printfn $"6) {String.Concat objs}"
// The example displays the following output:
// Concatenate 1, 2, and 3 objects:
// 1) -123
// 2) -123-123
// 3) -123-123-123
//
// Concatenate 4 objects and a variable length parameter list:
// 4) -123-123-123-123
// 5) -123-123-123-123-123
//
// Concatenate a 3-element object array:
// 6) -123-456-789
Class stringConcat5
Public Shared Sub Main()
Dim i As Integer = - 123
Dim o As [Object] = i
Dim objs() As [Object] = {-123, -456, -789}
Console.WriteLine("Concatenate 1, 2, and 3 objects:")
Console.WriteLine("1) {0}", [String].Concat(o))
Console.WriteLine("2) {0}", [String].Concat(o, o))
Console.WriteLine("3) {0}", [String].Concat(o, o, o))
Console.WriteLine(vbCrLf & "Concatenate 4 objects and a variable length parameter list:")
Console.WriteLine("4) {0}", String.Concat(o, o, o, o))
Console.WriteLine("5) {0}", String.Concat(o, o, o, o, o))
Console.WriteLine(vbCrLf & "Concatenate a 3-element object array:")
Console.WriteLine("6) {0}", [String].Concat(objs))
End Sub
End Class
'The example displays the following output:
' Concatenate 1, 2, and 3 objects:
' 1) -123
' 2) -123-123
' 3) -123-123-123
'
' Concatenate 4 objects and a variable length parameter list:
' 4) -123-123-123-123
' 5) -123-123-123-123-123
'
' Concatenate a 3-element object array:
' 6) -123-456-789
Açıklamalar
yöntemi, her nesnenin parametresiz ToString yöntemini çağırarak , arg1ve arg2 öğelerini birleştirirarg0; sınırlayıcı eklemez.
String.Empty herhangi bir null bağımsız değişkeninin yerine kullanılır.
Ayrıca bkz.
Şunlara uygulanır
Concat(String, String)
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
belirtilen iki örneğini Stringbirleştirir.
public:
static System::String ^ Concat(System::String ^ str0, System::String ^ str1);
public static string Concat(string str0, string str1);
public static string Concat(string? str0, string? str1);
static member Concat : string * string -> string
Public Shared Function Concat (str0 As String, str1 As String) As String
Parametreler
- str0
- String
Birleştirilmeye ilk dize.
- str1
- String
Birleştirilme ikinci dize.
Döndürülenler
ve str1birleştirmesistr0.
Örnekler
Aşağıdaki örnek bir kişinin adını, ikinci adını ve soyadını birleştirir.
using System;
public class ConcatTest {
public static void Main() {
// we want to simply quickly add this person's name together
string fName = "Simon";
string mName = "Jake";
string lName = "Harrows";
// because we want a name to appear with a space in between each name,
// put a space on the front of the middle, and last name, allowing for
// the fact that a space may already be there
mName = " " + mName.Trim();
lName = " " + lName.Trim();
// this line simply concatenates the two strings
Console.WriteLine("Welcome to this page, '{0}'!", string.Concat( string.Concat(fName, mName), lName ) );
}
}
// The example displays the following output:
// Welcome to this page, 'Simon Jake Harrows'!
open System
[<EntryPoint>]
let main _ =
// we want to simply quickly add this person's name together
let fName = "Simon"
let mName = "Jake"
let lName = "Harrows"
// because we want a name to appear with a space in between each name,
// put a space on the front of the middle, and last name, allowing for
// the fact that a space may already be there
let mName = " " + mName.Trim()
let lName = " " + lName.Trim()
// this line simply concatenates the two strings
printfn $"Welcome to this page, '{String.Concat(String.Concat(fName, mName), lName)}'!"
0
// The example displays the following output:
// Welcome to this page, 'Simon Jake Harrows'!
Public Class ConcatTest
Public Shared Sub Main()
Dim fName As String = "Simon"
Dim mName As String = "Jake"
Dim lName As String = "Harrows"
' We want to simply quickly add this person's name together.
' Because we want a name to appear with a space in between each name,
' we put a space on the front of the middle, and last name, allowing for
' the fact that a space may already be there.
mName = " " + mName.Trim()
lName = " " + lName.Trim()
' This line simply concatenates the two strings.
Console.WriteLine("Welcome to this page, '{0}'!", _
String.Concat(String.Concat(fName, mName), lName))
End Sub
End Class
' The example displays the following output:
' Welcome to this page, 'Simon Jake Harrows'!
Açıklamalar
yöntemi ve str1öğesini birleştirirstr0; sınırlayıcı eklemez.
Herhangi bir Empty null bağımsız değişken yerine bir dize kullanılır.
Ayrıca bkz.
Şunlara uygulanır
Concat(ReadOnlySpan<Object>)
- Kaynak:
- String.Manipulation.cs
Belirtilen nesne aralığındaki öğelerin dize gösterimlerini birleştirir.
public:
static System::String ^ Concat(ReadOnlySpan<System::Object ^> args);
public static string Concat(scoped ReadOnlySpan<object?> args);
static member Concat : ReadOnlySpan<obj> -> string
Public Shared Function Concat (args As ReadOnlySpan(Of Object)) As String
Parametreler
- args
- ReadOnlySpan<Object>
Birleşecek öğeleri içeren nesnelerin yayılma alanı.
Döndürülenler
içindeki öğelerin argsdeğerlerinin birleştirilmiş dize gösterimleri.
Şunlara uygulanır
Concat(Object, Object)
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
Belirtilen iki nesnenin dize gösterimlerini birleştirir.
public:
static System::String ^ Concat(System::Object ^ arg0, System::Object ^ arg1);
public static string Concat(object arg0, object arg1);
public static string Concat(object? arg0, object? arg1);
static member Concat : obj * obj -> string
Public Shared Function Concat (arg0 As Object, arg1 As Object) As String
Parametreler
- arg0
- Object
Birleşecek ilk nesne.
- arg1
- Object
Birleşecek ikinci nesne.
Döndürülenler
ve arg1değerlerinin birleştirilmiş dize gösterimleriarg0.
Örnekler
Aşağıdaki örnekte yöntemi gösterilmektedir Concat .
using System;
class stringConcat5 {
public static void Main() {
int i = -123;
Object o = i;
Object[] objs = new Object[] {-123, -456, -789};
Console.WriteLine("Concatenate 1, 2, and 3 objects:");
Console.WriteLine("1) {0}", String.Concat(o));
Console.WriteLine("2) {0}", String.Concat(o, o));
Console.WriteLine("3) {0}", String.Concat(o, o, o));
Console.WriteLine("\nConcatenate 4 objects and a variable length parameter list:");
Console.WriteLine("4) {0}", String.Concat(o, o, o, o));
Console.WriteLine("5) {0}", String.Concat(o, o, o, o, o));
Console.WriteLine("\nConcatenate a 3-element object array:");
Console.WriteLine("6) {0}", String.Concat(objs));
}
}
// The example displays the following output:
// Concatenate 1, 2, and 3 objects:
// 1) -123
// 2) -123-123
// 3) -123-123-123
//
// Concatenate 4 objects and a variable length parameter list:
// 4) -123-123-123-123
// 5) -123-123-123-123-123
//
// Concatenate a 3-element object array:
// 6) -123-456-789
open System
let i = -123
let o: obj = i
let objs: obj[] = [| -123; -456; -789 |]
printfn "Concatenate 1, 2, and 3 objects:"
printfn $"1) {String.Concat o}"
printfn $"2) {String.Concat(o, o)}"
printfn $"3) {String.Concat(o, o, o)}"
printfn "\nConcatenate 4 objects and a variable length parameter list:"
printfn $"4) {String.Concat(o, o, o, o)}"
printfn $"5) {String.Concat(o, o, o, o, o)}"
printfn "\nConcatenate a 3-element object array:"
printfn $"6) {String.Concat objs}"
// The example displays the following output:
// Concatenate 1, 2, and 3 objects:
// 1) -123
// 2) -123-123
// 3) -123-123-123
//
// Concatenate 4 objects and a variable length parameter list:
// 4) -123-123-123-123
// 5) -123-123-123-123-123
//
// Concatenate a 3-element object array:
// 6) -123-456-789
Class stringConcat5
Public Shared Sub Main()
Dim i As Integer = - 123
Dim o As [Object] = i
Dim objs() As [Object] = {-123, -456, -789}
Console.WriteLine("Concatenate 1, 2, and 3 objects:")
Console.WriteLine("1) {0}", [String].Concat(o))
Console.WriteLine("2) {0}", [String].Concat(o, o))
Console.WriteLine("3) {0}", [String].Concat(o, o, o))
Console.WriteLine(vbCrLf & "Concatenate 4 objects and a variable length parameter list:")
Console.WriteLine("4) {0}", String.Concat(o, o, o, o))
Console.WriteLine("5) {0}", String.Concat(o, o, o, o, o))
Console.WriteLine(vbCrLf & "Concatenate a 3-element object array:")
Console.WriteLine("6) {0}", [String].Concat(objs))
End Sub
End Class
'The example displays the following output:
' Concatenate 1, 2, and 3 objects:
' 1) -123
' 2) -123-123
' 3) -123-123-123
'
' Concatenate 4 objects and a variable length parameter list:
' 4) -123-123-123-123
' 5) -123-123-123-123-123
'
' Concatenate a 3-element object array:
' 6) -123-456-789
Açıklamalar
yöntemi ve parametresiz ToString yöntemini arg0 çağırarak ve arg1öğesini birleştirirarg0; sınırlayıcı eklemezarg1.
String.Empty herhangi bir null bağımsız değişkeninin yerine kullanılır.
Bağımsız değişkenlerden biri bir dizi başvurusuysa, yöntemi üyeleri yerine bu diziyi temsil eden bir dizeyi birleştirir (örneğin, "System.String[]").
Ayrıca bkz.
Şunlara uygulanır
Concat(String[])
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
Önemli
Bu API, CLS uyumlu değildir.
Belirtilen String dizinin öğelerini birleştirir.
public:
static System::String ^ Concat(... cli::array <System::String ^> ^ values);
public static string Concat(params string[] values);
public static string Concat(params string?[] values);
[System.CLSCompliant(false)]
public static string Concat(params string[] values);
static member Concat : string[] -> string
[<System.CLSCompliant(false)>]
static member Concat : string[] -> string
Public Shared Function Concat (ParamArray values As String()) As String
Parametreler
- values
- String[]
Dize örnekleri dizisi.
Döndürülenler
öğesinin birleştirilmiş öğeleri values.
- Öznitelikler
Özel durumlar
values, null'e eşittir.
Bellek yetersiz.
Örnekler
Aşağıdaki örnek, yönteminin Concat bir String dizi ile kullanımını gösterir.
using System;
public class Example
{
public static void Main()
{
// Make an array of strings. Note that we have included spaces.
string [] s = { "hello ", "and ", "welcome ", "to ",
"this ", "demo! " };
// Put all the strings together.
Console.WriteLine(string.Concat(s));
// Sort the strings, and put them together.
Array.Sort(s);
Console.WriteLine(string.Concat(s));
}
}
// The example displays the following output:
// hello and welcome to this demo!
// and demo! hello this to welcome
open System
// Make an array of strings. Note that we have included spaces.
let s =
[| "hello "; "and "; "welcome "; "to "
"this "; "demo! " |]
// Put all the strings together.
printfn $"{String.Concat s}"
// Sort the strings, and put them together.
Array.Sort s
printfn $"{String.Concat s}"
// The example displays the following output:
// hello and welcome to this demo!
// and demo! hello this to welcome
Public Class Example
Public Shared Sub Main()
' Make an array of strings. Note that we have included spaces.
Dim s As String() = { "hello ", "and ", "welcome ", "to ",
"this ", "demo! "}
' Put all the strings together.
Console.WriteLine(String.Concat(s))
' Sort the strings, and put them together.
Array.Sort(s)
Console.WriteLine(String.Concat(s))
End Sub
End Class
' The example displays the following output:
' hello and welcome to this demo!
' and demo! hello this to welcome
Açıklamalar
yöntemi içindeki valuesher nesneyi birleştirir; sınırlayıcı eklemez.
Dize Empty , dizideki herhangi bir null nesnenin yerine kullanılır.
Ayrıca bkz.
Şunlara uygulanır
Concat(ReadOnlySpan<String>)
- Kaynak:
- String.Manipulation.cs
belirtilen bir aralığının Stringöğelerini birleştirir.
public:
static System::String ^ Concat(ReadOnlySpan<System::String ^> values);
public static string Concat(scoped ReadOnlySpan<string?> values);
static member Concat : ReadOnlySpan<string> -> string
Public Shared Function Concat (values As ReadOnlySpan(Of String)) As String
Parametreler
- values
- ReadOnlySpan<String>
Örneklerden oluşan String bir aralık.
Döndürülenler
öğesinin birleştirilmiş öğeleri values.
Şunlara uygulanır
Concat(Object[])
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
Belirtilen Object dizideki öğelerin dize gösterimlerini birleştirir.
public:
static System::String ^ Concat(... cli::array <System::Object ^> ^ args);
public static string Concat(params object[] args);
public static string Concat(params object?[] args);
static member Concat : obj[] -> string
Public Shared Function Concat (ParamArray args As Object()) As String
Parametreler
- args
- Object[]
Birleştirmek için öğeleri içeren bir nesne dizisi.
Döndürülenler
içindeki öğelerin argsdeğerlerinin birleştirilmiş dize gösterimleri.
Özel durumlar
args, null'e eşittir.
Bellek yetersiz.
Örnekler
Aşağıdaki örnek, yönteminin Concat bir Object dizi ile kullanımını gösterir.
using System;
public class ConcatTest {
public static void Main() {
// Create a group of objects.
Test1 t1 = new Test1();
Test2 t2 = new Test2();
int i = 16;
string s = "Demonstration";
// Place the objects in an array.
object [] o = { t1, i, t2, s };
// Concatenate the objects together as a string. To do this,
// the ToString method of each of the objects is called.
Console.WriteLine(string.Concat(o));
}
}
// Create two empty test classes.
class Test1 {
}
class Test2 {
}
// The example displays the following output:
// Test116Test2Demonstration
open System
// Create two empty test classes.
type Test1() = class end
type Test2() = class end
// Create a group of objects.
let t1 = new Test1()
let t2 = new Test2()
let i = 16
let s = "Demonstration"
// Place the objects in an array.
let o: obj[] = [| t1; i; t2; s |]
// Concatenate the objects together as a string. To do this,
// the ToString method of each of the objects is called.
printfn $"{String.Concat o}"
// The example displays the following output:
// Test116Test2Demonstration
Public Class ConcatTest
Public Shared Sub Main()
Dim t1 As New Test1()
Dim t2 As New Test2()
Dim i As Integer = 16
Dim s As String = "Demonstration"
Dim o As Object() = {t1, i, t2, s}
' create a group of objects
' place the objects in an array
' concatenate the objects together as a string. To do this,
' the ToString method in the objects is called
Console.WriteLine(String.Concat(o))
End Sub
End Class
' imagine these test classes are full-fledged objects...
Class Test1
End Class
Class Test2
End Class
Açıklamalar
yöntemi, bu nesnenin args parametresiz ToString yöntemini çağırarak içindeki her nesneyi birleştirir; sınırlayıcı eklemez.
String.Empty dizideki herhangi bir null nesnenin yerine kullanılır.
Arayanlara Notlar
Bu yöntem C++ kodu tarafından çağrılmaz. C++ derleyicisi, çağrısı olarak dört veya daha fazla nesne parametresi içeren çağrısına Concat(Object, Object, Object, Object)yönelik çağrıları Concat çözümler.
Ayrıca bkz.
Şunlara uygulanır
Concat(Object)
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
Belirtilen nesnenin dize gösterimini oluşturur.
public:
static System::String ^ Concat(System::Object ^ arg0);
public static string Concat(object arg0);
public static string Concat(object? arg0);
static member Concat : obj -> string
Public Shared Function Concat (arg0 As Object) As String
Parametreler
- arg0
- Object
Temsil etmek istediğiniz nesne veya null.
Döndürülenler
veya ise nullarg0 değerinin arg0Empty dize gösterimi.
Örnekler
Aşağıdaki örnekte yöntemi gösterilmektedir Concat .
using System;
class stringConcat5 {
public static void Main() {
int i = -123;
Object o = i;
Object[] objs = new Object[] {-123, -456, -789};
Console.WriteLine("Concatenate 1, 2, and 3 objects:");
Console.WriteLine("1) {0}", String.Concat(o));
Console.WriteLine("2) {0}", String.Concat(o, o));
Console.WriteLine("3) {0}", String.Concat(o, o, o));
Console.WriteLine("\nConcatenate 4 objects and a variable length parameter list:");
Console.WriteLine("4) {0}", String.Concat(o, o, o, o));
Console.WriteLine("5) {0}", String.Concat(o, o, o, o, o));
Console.WriteLine("\nConcatenate a 3-element object array:");
Console.WriteLine("6) {0}", String.Concat(objs));
}
}
// The example displays the following output:
// Concatenate 1, 2, and 3 objects:
// 1) -123
// 2) -123-123
// 3) -123-123-123
//
// Concatenate 4 objects and a variable length parameter list:
// 4) -123-123-123-123
// 5) -123-123-123-123-123
//
// Concatenate a 3-element object array:
// 6) -123-456-789
open System
let i = -123
let o: obj = i
let objs: obj[] = [| -123; -456; -789 |]
printfn "Concatenate 1, 2, and 3 objects:"
printfn $"1) {String.Concat o}"
printfn $"2) {String.Concat(o, o)}"
printfn $"3) {String.Concat(o, o, o)}"
printfn "\nConcatenate 4 objects and a variable length parameter list:"
printfn $"4) {String.Concat(o, o, o, o)}"
printfn $"5) {String.Concat(o, o, o, o, o)}"
printfn "\nConcatenate a 3-element object array:"
printfn $"6) {String.Concat objs}"
// The example displays the following output:
// Concatenate 1, 2, and 3 objects:
// 1) -123
// 2) -123-123
// 3) -123-123-123
//
// Concatenate 4 objects and a variable length parameter list:
// 4) -123-123-123-123
// 5) -123-123-123-123-123
//
// Concatenate a 3-element object array:
// 6) -123-456-789
Class stringConcat5
Public Shared Sub Main()
Dim i As Integer = - 123
Dim o As [Object] = i
Dim objs() As [Object] = {-123, -456, -789}
Console.WriteLine("Concatenate 1, 2, and 3 objects:")
Console.WriteLine("1) {0}", [String].Concat(o))
Console.WriteLine("2) {0}", [String].Concat(o, o))
Console.WriteLine("3) {0}", [String].Concat(o, o, o))
Console.WriteLine(vbCrLf & "Concatenate 4 objects and a variable length parameter list:")
Console.WriteLine("4) {0}", String.Concat(o, o, o, o))
Console.WriteLine("5) {0}", String.Concat(o, o, o, o, o))
Console.WriteLine(vbCrLf & "Concatenate a 3-element object array:")
Console.WriteLine("6) {0}", [String].Concat(objs))
End Sub
End Class
'The example displays the following output:
' Concatenate 1, 2, and 3 objects:
' 1) -123
' 2) -123-123
' 3) -123-123-123
'
' Concatenate 4 objects and a variable length parameter list:
' 4) -123-123-123-123
' 5) -123-123-123-123-123
'
' Concatenate a 3-element object array:
' 6) -123-456-789
Açıklamalar
yöntemi parametresiz Concat(Object)ToString yöntemini çağırarak dize olarak temsil ederarg0.
Ayrıca bkz.
Şunlara uygulanır
Concat(IEnumerable<String>)
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
türündeki Stringbir derlenmiş IEnumerable<T> koleksiyonun üyelerini birleştirir.
public:
static System::String ^ Concat(System::Collections::Generic::IEnumerable<System::String ^> ^ values);
public static string Concat(System.Collections.Generic.IEnumerable<string> values);
public static string Concat(System.Collections.Generic.IEnumerable<string?> values);
[System.Runtime.InteropServices.ComVisible(false)]
public static string Concat(System.Collections.Generic.IEnumerable<string> values);
static member Concat : seq<string> -> string
[<System.Runtime.InteropServices.ComVisible(false)>]
static member Concat : seq<string> -> string
Public Shared Function Concat (values As IEnumerable(Of String)) As String
Parametreler
- values
- IEnumerable<String>
uygulayan IEnumerable<T> ve genel tür bağımsız değişkeni olan bir koleksiyon nesnesi.String
Döndürülenler
içindeki valuesbirleştirilmiş dizeler veya Empty boş IEnumerable(Of String)isevalues.
- Öznitelikler
Özel durumlar
values, null'e eşittir.
Örnekler
Aşağıdaki örnek, 100'den küçük veya buna eşit olan asal sayıları hesaplamak için Eratosthenes Sieve algoritmasını kullanır. Sonucu türündeki Stringbir List<T> nesnesine atar ve ardından yöntemine Concat(IEnumerable<String>) geçirir.
using System;
using System.Collections.Generic;
public class Example
{
public static void Main()
{
int maxPrime = 100;
IEnumerable<String> primeList = GetPrimes(maxPrime);
Console.WriteLine("Primes less than {0}:", maxPrime);
Console.WriteLine(" {0}", String.Concat(primeList));
}
private static IEnumerable<String> GetPrimes(int maxPrime)
{
Array values = Array.CreateInstance(typeof(int),
new int[] { maxPrime - 1}, new int[] { 2 });
// Use Sieve of Erathsthenes to determine prime numbers.
for (int ctr = values.GetLowerBound(0); ctr <= (int) Math.Ceiling(Math.Sqrt(values.GetUpperBound(0))); ctr++)
{
if ((int) values.GetValue(ctr) == 1) continue;
for (int multiplier = ctr; multiplier <= maxPrime / 2; multiplier++)
if (ctr * multiplier <= maxPrime)
values.SetValue(1, ctr * multiplier);
}
List<String> primes = new List<String>();
for (int ctr = values.GetLowerBound(0); ctr <= values.GetUpperBound(0); ctr++)
if ((int) values.GetValue(ctr) == 0)
primes.Add(ctr.ToString() + " ");
return primes;
}
}
// The example displays the following output:
// Primes less than 100:
// 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
open System
let getPrimes maxPrime =
let values = Array.CreateInstance(typeof<int>, [| maxPrime - 1|], [| 2 |])
// Use Sieve of Erathsthenes to determine prime numbers.
for i = values.GetLowerBound 0 to values.GetUpperBound 0 |> float |> sqrt |> ceil |> int do
if values.GetValue i :?> int <> 1 then
for multiplier = i to maxPrime / 2 do
if i * multiplier <= maxPrime then
values.SetValue(1, i * multiplier)
seq {
for i = values.GetLowerBound 0 to values.GetUpperBound 0 do
if values.GetValue i :?> int = 0 then
string i + " "
}
let maxPrime = 100
let primeList = getPrimes maxPrime
printfn $"Primes less than {maxPrime}:"
printfn $" {String.Concat primeList}"
// The example displays the following output:
// Primes less than 100:
// 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
Imports System.Collections.Generic
Module Example
Public Sub Main()
Dim maxPrime As Integer = 100
Dim primeList As IEnumerable(Of String) = GetPrimes(maxPrime)
Console.WriteLine("Primes less than {0}:", maxPrime)
Console.WriteLine(" {0}", String.Concat(primeList))
End Sub
Private Function GetPrimes(maxPrime As Integer) As IEnumerable(Of String)
Dim values As Array = Array.CreateInstance(GetType(Integer), _
New Integer() { maxPrime - 1}, New Integer(){ 2 })
' Use Sieve of Erathsthenes to determine prime numbers.
For ctr As Integer = values.GetLowerBound(0) To _
CInt(Math.Ceiling(Math.Sqrt(values.GetUpperBound(0))))
If CInt(values.GetValue(ctr)) = 1 Then Continue For
For multiplier As Integer = ctr To maxPrime \ 2
If ctr * multiplier <= maxPrime Then values.SetValue(1, ctr * multiplier)
Next
Next
Dim primes As New List(Of String)
For ctr As Integer = values.GetLowerBound(0) To values.GetUpperBound(0)
If CInt(values.GetValue(ctr)) = 0 Then primes.Add(ctr.ToString() + " ")
Next
Return primes
End Function
End Module
' The example displays the following output:
' Primes less than 100:
' 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
Açıklamalar
yöntemi içindeki valuesher nesneyi birleştirir; sınırlayıcı eklemez. öğesinin valuesher üyesi arasında bir sınırlayıcı belirtmek için yöntemini çağırın Join(String, IEnumerable<String>) .
içindeki Empty herhangi bir null öğenin valuesyerine bir dize kullanılır.
Boş bir ise values yöntemi döndürürString.Empty.IEnumerable(Of String) ise valuesnullyöntemi bir ArgumentNullException özel durum oluşturur.
Concat(IEnumerable<String>) , öğeleri bir dize dizisine dönüştürmeden bir IEnumerable(Of String) koleksiyondaki her öğeyi birleştirmenize olanak tanıyan bir kolaylık yöntemidir. Özellikle Language-Integrated Sorgu (LINQ) sorgu ifadelerinde kullanışlıdır. Aşağıdaki örnek, alfabenin büyük veya küçük harflerini içeren bir List(Of String) nesneyi, belirli bir harfe eşit veya daha büyük harfleri (örnekte "M" olan) seçen bir lambda ifadesine geçirir.
IEnumerable(Of String) yöntemi tarafından Enumerable.Where döndürülen koleksiyon, sonucu tek bir dize olarak görüntülemek için yöntemine geçirilirConcat(IEnumerable<String>).
using System;
using System.Collections.Generic;
using System.Linq;
public class Example
{
public static void Main()
{
string output = String.Concat( GetAlphabet(true).Where( letter =>
letter.CompareTo("M") >= 0));
Console.WriteLine(output);
}
private static List<string> GetAlphabet(bool upper)
{
List<string> alphabet = new List<string>();
int charValue = upper ? 65 : 97;
for (int ctr = 0; ctr <= 25; ctr++)
alphabet.Add(((char)(charValue + ctr)).ToString());
return alphabet;
}
}
// The example displays the following output:
// MNOPQRSTUVWXYZ
// This example uses the F# Seq.filter function instead of Linq.
open System
let getAlphabet upper =
let charValue = if upper then 65 else 97
seq {
for i = 0 to 25 do
charValue + i |> char |> string
}
getAlphabet true
|> Seq.filter (fun letter -> letter.CompareTo "M" >= 0)
|> String.Concat
|> printfn "%s"
// The example displays the following output:
// MNOPQRSTUVWXYZ
Imports System.Collections.Generic
Imports System.Linq
Module modMain
Public Sub Main()
Dim output As String = String.Concat(GetAlphabet(true).Where(Function(letter) _
letter >= "M"))
Console.WriteLine(output)
End Sub
Private Function GetAlphabet(upper As Boolean) As List(Of String)
Dim alphabet As New List(Of String)
Dim charValue As Integer = CInt(IIf(upper, 65, 97))
For ctr As Integer = 0 To 25
alphabet.Add(ChrW(charValue + ctr).ToString())
Next
Return alphabet
End Function
End Module
' The example displays the following output:
' MNOPQRSTUVWXYZ
Şunlara uygulanır
Concat(ReadOnlySpan<Char>, ReadOnlySpan<Char>)
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
Belirtilen iki salt okunur karakter aralığının dize gösterimlerini birleştirir.
public:
static System::String ^ Concat(ReadOnlySpan<char> str0, ReadOnlySpan<char> str1);
public static string Concat(ReadOnlySpan<char> str0, ReadOnlySpan<char> str1);
static member Concat : ReadOnlySpan<char> * ReadOnlySpan<char> -> string
Public Shared Function Concat (str0 As ReadOnlySpan(Of Char), str1 As ReadOnlySpan(Of Char)) As String
Parametreler
- str0
- ReadOnlySpan<Char>
Birleştirmek için ilk salt okunur karakter aralığı.
- str1
- ReadOnlySpan<Char>
Birleştirmek için ikinci salt okunur karakter aralığı.
Döndürülenler
ve str1değerlerinin birleştirilmiş dize gösterimleristr0.
Şunlara uygulanır
Concat<T>(IEnumerable<T>)
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
- Kaynak:
- String.Manipulation.cs
Bir uygulamanın üyelerini birleştirir IEnumerable<T> .
public:
generic <typename T>
static System::String ^ Concat(System::Collections::Generic::IEnumerable<T> ^ values);
public static string Concat<T>(System.Collections.Generic.IEnumerable<T> values);
[System.Runtime.InteropServices.ComVisible(false)]
public static string Concat<T>(System.Collections.Generic.IEnumerable<T> values);
static member Concat : seq<'T> -> string
[<System.Runtime.InteropServices.ComVisible(false)>]
static member Concat : seq<'T> -> string
Public Shared Function Concat(Of T) (values As IEnumerable(Of T)) As String
Tür Parametreleri
- T
üyelerinin valuestürü.
Parametreler
- values
- IEnumerable<T>
Arabirimini uygulayan IEnumerable<T> bir koleksiyon nesnesi.
Döndürülenler
içindeki valuesbirleştirilmiş üyeler.
- Öznitelikler
Özel durumlar
values, null'e eşittir.
Örnekler
Aşağıdaki örnek, bir hayvanın adını ve ait olduğu sırayı içeren çok basit Animal bir sınıfı tanımlar. Ardından bir List<T> nesneyi bir dizi Animal nesne içerecek şekilde tanımlar.
Enumerable.Where Uzantı yöntemi, özelliği "Kemirgen" değerine eşit olan Order nesneleri ayıklamak Animal için çağrılır. Sonuç yöntemine Concat<T>(IEnumerable<T>) geçirilir ve konsolda görüntülenir.
using System;
using System.Collections.Generic;
using System.Linq;
public class Animal
{
public string Kind;
public string Order;
public Animal(string kind, string order)
{
this.Kind = kind;
this.Order = order;
}
public override string ToString()
{
return this.Kind;
}
}
public class Example
{
public static void Main()
{
List<Animal> animals = new List<Animal>();
animals.Add(new Animal("Squirrel", "Rodent"));
animals.Add(new Animal("Gray Wolf", "Carnivora"));
animals.Add(new Animal("Capybara", "Rodent"));
string output = String.Concat(animals.Where( animal =>
(animal.Order == "Rodent")));
Console.WriteLine(output);
}
}
// The example displays the following output:
// SquirrelCapybara
// This example uses the F# Seq.filter function instead of Linq.
open System
type Animal =
{ Kind: string
Order: string }
override this.ToString() =
this.Kind
let animals = ResizeArray()
animals.Add { Kind = "Squirrel"; Order = "Rodent" }
animals.Add { Kind = "Gray Wolf"; Order = "Carnivora" }
animals.Add { Kind = "Capybara"; Order = "Rodent" }
Seq.filter (fun animal -> animal.Order = "Rodent")
|> String.Concat
|> printfn "%s"
// The example displays the following output:
// SquirrelCapybara
Imports System.Collections.Generic
Public Class Animal
Public Kind As String
Public Order As String
Public Sub New(kind As String, order As String)
Me.Kind = kind
Me.Order = order
End Sub
Public Overrides Function ToString() As String
Return Me.Kind
End Function
End Class
Module Example
Public Sub Main()
Dim animals As New List(Of Animal)
animals.Add(New Animal("Squirrel", "Rodent"))
animals.Add(New Animal("Gray Wolf", "Carnivora"))
animals.Add(New Animal("Capybara", "Rodent"))
Dim output As String = String.Concat(animals.Where(Function(animal) _
animal.Order = "Rodent"))
Console.WriteLine(output)
End Sub
End Module
' The example displays the following output:
' SquirrelCapybara
Açıklamalar
yöntemi içindeki valuesher nesneyi birleştirir; sınırlayıcı eklemez.
Herhangi bir Empty null bağımsız değişken yerine bir dize kullanılır.
Concat<T>(IEnumerable<T>) , önce öğeleri dizelere dönüştürmeden bir koleksiyondaki her öğeyi birleştirmenize olanak tanıyan bir IEnumerable<T> kolaylık yöntemidir. Örnekte gösterildiği gibi Language-Integrated Sorgu (LINQ) sorgu ifadelerinde özellikle yararlıdır. Koleksiyondaki IEnumerable<T> her nesnenin dize gösterimi, bu nesnenin ToString yöntemi çağrılarak türetilir.