Используйте выход HTML.
Так в Вашем примере:
/**
* Returns true if the specified string contains "*/".
*/
public boolean containsSpecialSequence(String str)
/
Escape как "/" символ.
Javadoc должен вставить завершенную последовательность, в безопасности в HTML, который он генерирует, и это должно представить как "* /" в Вашем браузере.
, Если Вы хотите быть очень осторожными, Вы могли бы выйти из обоих символов: */
переводит в */
Редактирование:
Продолжите: кажется, что я могу использовать & #47; для наклонной черты. Единственный недостаток - то, что это не все это читаемое когда представление код непосредственно.
Так? Точка не, чтобы Ваш код был читаем, точка для Вашего кода документация , чтобы быть читаемой. Большинство комментариев Javadoc встраивает сложный HTML для explaination. Черт, эквивалентные предложения C# полная библиотека XML-тэга. Я видел некоторые довольно сложные структуры там, позвольте мне сказать Вам.
Редактирование 2: , Если это беспокоит Вас слишком много, Вы могли бы встроить non-javadoc встроенный комментарий, который объясняет кодирование:
/**
* Returns true if the specified string contains "*/".
*/
// returns true if the specified string contains "*/"
public boolean containsSpecialSequence(String str)
Max is used to find the maximum value of a property. Once you have the maximum value you can select those objects whose value matches using the Where clause.
var maxZ = list.Max( obj => obj.Z );
var maxObj = list.Where( obj => obj.Z == maxZ );
To get the object with the greatest Z value you sort on the Z value in descending order and get the first item:
TypeOfObject oldest = list.OrderByDescending(x => x.Z).First();
Edit:
Changed it to use the IEnumerable.OrderByDescending method instead of List.Sort.
Edit 2:
If you want performance, this is about four times faster than the fastest LINQ solution:
int high = Int32.MinValue;
List<TypeOfObject> highest = new List<TypeOfObject>();
foreach (TypeOfObject v in list) {
if (v.Z >= high) {
if (v.Z > high) highest.Clear();
high = v.Z;
highest.Add(v);
}
}
If can implement either IComparable
or IComparable
on your class along these lines:
public Int32 CompareTo(MyClass other) {
return Z.CompareTo(other.Z);
}
You can get the maximum value simply by calling (this will require using System.Linq
):
MyClass maxObject = list.Max();
This will only perform a single pass over your list of values.
int maxAge = myList.Max(obj => obj.Z);
The parameter used is a lambda expression. This expression indicates which property to use(in this case, Z) to get the max value. This will get the maximum age. If you want the object which has the greatest age, you could sort by age and get the first result:
MyType maxItem = myList.OrderByDescending(obj => obj.Z).First();
If you do it this way, note that if two or more items all have the maximum age, only one of them is selected.
It will largely depend on the type of X, if it is comparable:
var array = new[] {
new { X = "a", Y = "a", Z = 1 },
new { X = "b", Y = "b", Z = 2 }
};
var max = array.Max(x => x.Z);
Console.WriteLine(max);