PDA

View Full Version : تبدیل کد مرتب سازی جاوا به سی شارپ



farzane-
شنبه 25 خرداد 1398, 02:09 صبح
سلام به همه
در حال تبدیل یک برنامه از جاوا به سی شارپ هستم
همه توابع تکمیل شده و فقط یک تیکه کد باقی مونده که نمی دونم از چه روشی این کد رو به سی شارپ تبدیل کنمکد زیر برای مرتب سازی تراکنش ها در جاوا استفاده میشه. ممنون میشم در تبدیل این کد به سی شارپ راهنماییم کنید


Collections: IComparable<Transaction>;
Collections.sort(dataset.getTransactions(), new Comparator<Transaction>(){
Override
/**
* Compare two transactions
*/
public int compare(Transaction t1, Transaction t2) {
/**
* Codes
*/
}
});

farhad_shiri_ex
شنبه 25 خرداد 1398, 08:28 صبح
سلام به همه
در حال تبدیل یک برنامه از جاوا به سی شارپ هستم
همه توابع تکمیل شده و فقط یک تیکه کد باقی مونده که نمی دونم از چه روشی این کد رو به سی شارپ تبدیل کنمکد زیر برای مرتب سازی تراکنش ها در جاوا استفاده میشه. ممنون میشم در تبدیل این کد به سی شارپ راهنماییم کنید


Collections: IComparable<Transaction>;
Collections.sort(dataset.getTransactions(), new Comparator<Transaction>(){
Override
/**
* Compare two transactions
*/
public int compare(Transaction t1, Transaction t2) {
/**
* Codes
*/
}
});



با سلام

public class Transaction : IEquatable<Transaction> , IComparable<Transaction>
{

//must be overload this method
public override string ToString()
{
return "your code";
}
public override bool Equals(object obj)
{
return false ; //your strategy code
}
public int CompareTo(Transaction trans)
{
if (trans == null)
return 1;
else
return this.trans.CompareTo(trans.yourField);
}
public override int GetHashCode()
{
return yourField;//or other strategy for hashcode
}
public bool Equals(Transaction other)
{
if (other == null) return false;
return (this.yourField.Equals(other.yourField));
}
// Should also override == and != operators.


}




public class Example
{
public static void Main()
{
// Create a list of parts.
List<Transaction> transactions = dataset.getTransactions();


// parts.Sort();


parts.Sort(delegate(Transaction x, Transaction y)
{
return ; //your compare strategy is here!
});


// This will call the overridden
// ToString method in the Transaction class.
Console.WriteLine("\nBefore sort:");
foreach (Transaction transObj in transactions)
{
Console.WriteLine(transObj);
}


}
}