C# 0 The Complete Reference


= =  operator. Normally, when the  = =



Download 4,07 Mb.
Pdf ko'rish
bet224/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   220   221   222   223   224   225   226   227   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

= =

 operator. Normally, when the 



= = 

operator is applied to object references, it determines if both references refer to the same 

object. This differs for objects of type 

string

. When the 



= =

 is applied to two 



string

 references, 

the contents of the strings, themselves, are compared for equality. The same is true for the 

!=

operator: When comparing 



string

 objects, the contents of the strings are compared. For other 

types of string comparisons, you will need to use the 

CompareTo( )

 method.


Here is a program that demonstrates several string operations:

// Some string operations.

using System;

class StrOps {

  static void Main() {

    string str1 =

      "When it comes to .NET programming, C# is #1.";

    string str2 = string.Copy(str1);

    string str3 = "C# strings are powerful.";

    string strUp, strLow;

    int result, idx;

    Console.WriteLine("str1: " + str1);

    Console.WriteLine("Length of str1: " +

                       str1.Length);

    // Create upper- and lowercase versions of str1.

    strLow = str1.ToLower();

    strUp =  str1.ToUpper();

    Console.WriteLine("Lowercase version of str1:\n    " +

                      strLow);

    Console.WriteLine("Uppercase version of str1:\n    " +

                      strUp);

    Console.WriteLine();

    // Display str1, one char at a time.

    Console.WriteLine("Display str1, one char at a time.");

    for(int i=0; i < str1.Length; i++)

      Console.Write(str1[i]);

    Console.WriteLine("\n");

    // Compare strings.

    if(str1 == str2)

      Console.WriteLine("str1 == str2");

    else

      Console.WriteLine("str1 != str2");

    if(str1 == str3)

      Console.WriteLine("str1 == str3");

    else

      Console.WriteLine("str1 != str3");

www.freepdf-books.com



Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   220   221   222   223   224   225   226   227   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish