2017-05-02 18 views
5
ben 3 seans değerleri Oturum [ "Ad"] bitiştirmek gerekir

ile oturum değerlerini birleştirmek nasıl, Oturum [ "Göbek Adı"], Oturum [ "Soyadı"] arasına boşluk.bir boşluk

 Labelname.Text = String.Concat(this.Session["First Name"],"", this.Session["Middle Name"],"", this.Session["Last Name"]); 

ama ben sonuç almak:

+0

Çünkü alan kullanmıyorsunuz. İle değiştirin " ". Veya ' " ''yerine' arasında' daha iyi kullanılması String.Format – Andrei

+0

kullanım"' – Matthiee

cevap

0

" "ile"" Değiştir firstnamemiddlenamelastname

Aşağıdaki çalıştı.

Labelname.Text = String.Concat(this.Session["First Name"]," ", this.Session["Middle Name"]," ", this.Session["Last Name"]); 

Diğer Yolu:

Labelname.Text = this.Session["First Name"].ToString()+" "+ this.Session["Middle Name"].ToString()+" "this.Session["Last Name"]).ToString(); 

Umarım yardımcı olur!

+0

ben ..ama dint iş –

+0

yerine bu şekilde başka bir yol denemek @AnitaMathew olduğunu çalıştım. –

3

Boşlukları değil, boş dizeleri birleştiriyorsunuz.

Labelname.Text = String.Concat(this.Session["First Name"]," ", this.Session["Middle Name"]," ", this.Session["Last Name"]); 

C# dizeleri bitiştirmek için başka yolları da vardır:

var empty = "" 
var space = " " 

Yani, örnek değiştirmeniz gerekir.

+ operatörü kullanarak: C 6. interpolated dizeleri kullanma

Labelname.Text = this.Session["First Name"] + " " + this.Session["Middle Name"] + " " + this.Session["Last Name"]; 

özelliği:

string.Join kullanma:

Labelname.Text = string.Join(" ", new []{ this.Session["First Name"], this.Session["Middle Name"], this.Session["Last Name"]}); 
0

basit bir çözüm String.format kullanmaktır

string.Format("{0} {1} {2}", this.Session["First Name"], this.Session["Middle Name"], this.Session["Last Name"]); 
0

kullanma C# v6 +

var firstName = this.Session["First Name"].ToString(); 
var middleName = this.Session["Middle Name"].ToString(); 
var lastName = this.Session["Last Name"].ToString(); 

Labelname.Text = $"{firstName} {middleName} {lastName}"; 
0

Sen yönteminin altında olan deneyebilirsiniz.
Labelname.Text = this.Session [ "Ad"]. ToString() + "" + this.Session [ "Göbek Adı"]. ToString() + "" + this.Session [ "Soyadı"]. .ToString();