انواع متدهای های زیر را تحقیق کنید و جالت های مختلف چگونه است ؟

 

string.compare (A,B) {  >0   =>  A>B


                        0=       A=B

   <0       A<> <>

 

جواب :



public static int Compare(
	string strA,
	string strB,
	bool ignoreCase
)

Parameters

strA
Type: System.String

The first string to compare.

strB
Type: System.String

The second string to compare.

ignoreCase
Type: System.Boolean

true to ignore case during the comparison; otherwise, false.

Return Value

Type: System.Int32
A 32-bit signed integer that indicates the lexical relationship between the two comparands.

Value

Condition

Less than zero

strA is less than strB.

Zero

strA equals strB.

Greater than zero

strA is greater than strB.

--------------------

string testString = "Test";
string anotherString = "Another";

if (testString.CompareTo(anotherString) == 0) {}
if (testString.Equals(anotherString)) {}
if (testString == anotherStirng) {}


---------------------------------
public static int Compare(string strA, string strB) { return CultureInfo.CurrentCulture.CompareInfo.Compare(strA, strB, CompareOptions.None); } public int CompareTo(string strB) { if (strB == null) { return 1; } return CultureInfo.CurrentCulture.CompareInfo.Compare(this, strB, CompareOptions.None); }

----------------------------------


string s1 = "String to compare.";
string s2 = "String to compare.";
string s3 = "String to Compare.";   // Note the capital 'C'
bool result;
 
result = s1 == s2;                  // result = true
result = s1 == s3;                  // result = false
result = s1 != s2;                  // result = false
result = s1 != s3;                  // result = true
Return ValueMeaning
ZeroThe strings are equal.
Less than ZeroThe first string is less than the second.
More than ZeroThe first is greater than the second or the second string is null.

This can be clarified with an example:

string animal1 = "Cat";
string animal2 = "Dog";
int result;
 
result = animal1.CompareTo("Cat");          // result is zero
result = animal2.CompareTo("Cat");          // result is greater than zero
result = animal1.CompareTo(animal2);        // result is less than zero
string animal = null;
int result;
 
result = animal.CompareTo("Cat");           // Causes an exception
string animal1 = "Cat";
string animal2 = "Dog";
int result;
 
result = String.Compare(animal1, "Cat");    // result is zero
result = String.Compare(animal2, "Cat");    // result is greater than zero
result = String.Compare(animal1, animal2);  // result is less than zero

string animal = "Cat";
int result;
 
result = String.Compare(animal, null);      // result is greater than zero
result = String.Compare(null, animal);      // result is less than zero
result = String.Compare(null, null);        // result is zero
string animal1 = "Cat";
string animal2 = "cat";                             // Note use of lower case
int result;
 
result = String.Compare(animal1, animal2, true);    // Strings are equal
result = String.Compare(animal1, animal2, false);   // Strings are not equal

-------------------------

 




متدی بنام  AverageByColor بنام Pro اضافه شود به این صورت که یک رنگ به عنوان پارامتر

از ورودی دریافت کند و میانگین قیمت کالاهایی از آن رنگ را محاسبه و چاپ کند.

( به طور مثال ۱۰ تا کالا ۴ تا رنگ قرمز بگیرد جمع کالا و میانگین کالاها را محاسبه کند )