Регулярные короткие заметки по C# и .NET.
Просто о сложном для каждого.
admin - @haarrp
Post #146
771

C# @csharp_1001_notes
Showing posts older than #147 · Back to latest

SampleNamespace#post
{
class SampleClass
{
public void SampleMethod()
{
System.Console.WriteLine(
"SampleMethod inside SampleNamespace");
}
}
}

Accum("abcd") ➞ "A-Bb-Ccc-Dddd"
Accum("RqaEzty") ➞ "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"
Accum("cwAt") ➞ "C-Ww-Aaa-Tttt"
🏆 Leave your solutions in the comments. The solution will be posted below in a couple of hours 👇
yield keyword actually does quite a lot here. It creates a state machine "under the covers" that remembers where you were on each additional cycle of the function and picks up from there.IEnumerable<T> interface. If a calling function starts foreaching over this object, the function is called again until it "yields" result based on some predicate.IEnumerable and IEnumerator objects to do stuff like this.

abstract modifier indicates that the thing being modified has a missing or incomplete implementation. The abstract modifier can be used with classes, methods, properties, indexers, and events.abstract keyword and can be used only as a Base class.sealed modifier prevents a class from being inherited and the abstract modifier requires a class to be inherited.
LargestGap(new int[] { 9, 4, 26, 26, 0, 0, 5, 20, 6, 25, 5 }) ➞ 11
// After sorting get { 0, 0, 4, 5, 5, 6, 9, 20, 25, 26, 26 }
// Largest gap of 11 between 9 and 20
LargestGap(new int[] { 14, 13, 7, 1, 4, 12, 3, 7, 7, 12, 11, 5, 7 }) ➞ 4
// After sorting get { 1, 3, 4, 5, 7, 7, 7, 7, 11, 12, 12, 13, 14 }
// Largest gap of 4 between 7 and 11
🏆 Leave your solutions in the comments. The solution will be posted below in a couple of hours 👇
IEnumerable. That interface basically lets you use the class in a foreach statement (in C#).

System.Value Type.System.Object Type.
isFactorial(2) ➞ true🏆 Leave your solutions in the comments. The solution will be posted below in a couple of hours 👇
// 2 = 2 * 1 = 2!
isFactorial(27) ➞ false
isFactorial(24) ➞ true
// 24 = 4 * 3 * 2 * 1 = 4!

Finalize() method.Collect() method of the Garbage Collector class to forcefully execute Garbage Collector).
