List<String> strList = new ArrayList<String>();
List<Integer> intList = new ArrayList<Integer>();
bool areSame = strList.getClass() == intList.getClass();
System.out.println(areSame);
List<String> strList = new ArrayList<String>();
strList.add("stringValue");
String str = strList.get(0);
List list = new ArrayList();
list.add("stringValue");
String x = (String) list.get(0);
public struct Quad
{
int X1;
int X2;
int Y1;
int Y2;
}
List<Integer> intList = new ArrayList<Integer>();
List<Integer> intList = new ArrayList<int>();
struct Point
{
public int x;
public int y;
}
unsafe static void PointerMethod()
{
Point point;
Point* p = &point;
p->x = 100;
p->y = 200;
Point point2;
Point* p2 = &point2;
(*p2).x = 100;
(*p2).y = 200;
}
public class TestClass
{
public int TotalSum
{
get
{
return Count * Price;
}
}
// -
public int Count
{
get;
set;
}
public int Price
{
get
{
return 50;
}
}
}
public class TestClass
{
/*
*
*/
private int <Count>k__BackingField;
// -
public int Count
{
get { return <Count>k__BackingField; }
set { <Count>k__BackingField = value; }
}
}
public class TestClass
{
public delegate int BinaryOp(int arg1, int arg2);
public int Add(int a, int b)
{
return a + b;
}
public int Multiply(int first, int second)
{
return first * second;
}
public void TestDelegates()
{
BinaryOp op = new BinaryOp(Add);
int result = op(1, 2);
Console.WriteLine(result);
//: 3
op = new BinaryOp(Multiply);
result = op(2, 5);
Console.WriteLine(result);
//: 10
}
}
int Add(int arg1, int arg2)
{
return arg1 + arg2;
}
void TestFP()
{
int (*fpAdd)(int, int);
fpAdd = &Add; //
int three = fpAdd(1, 2); //
}
public class MyClass
{
private string _value;
public delegate void ChangingEventhandler(string oldValue);
public event ChangingEventhandler Changing;
public void OnChanging(string oldvalue)
{
ChangingEventhandler handler = Changing;
if (handler != null)
handler(oldvalue);
}
public string Value
{
get
{
return _value;
}
set
{
OnChanging(_value);
_value = value;
}
}
public void TestEvent()
{
MyClass instance = new MyClass();
instance.Changing += new ChangingEventhandler(instance_Changing);
instance.Value = "new string value";
// instance_Changing
}
void instance_Changing(string oldValue)
{
Console.WriteLine(oldValue);
}
}
public class TestClass
{
public delegate int BinaryOp(int arg1, int arg2);
public void TestDelegates()
{
BinaryOp op = new BinaryOp(delegate(int a, int b)
{
return a + b;
});
int result = op(1, 2);
Console.WriteLine(result);
//: 3
}
}
public class TestClass
{
public delegate int BinaryOp(int arg1, int arg2);
public void TestDelegates()
{
BinaryOp op = new BinaryOp((a, b) => a + b);
int result = op(1, 2);
Console.WriteLine(result);
//: 3
}
}
public class MyClass
{
/*
*
*/
public void TestEvent()
{
MyClass instance = new MyClass();
instance.Changing += (o) => Console.WriteLine(o);
instance.Value = "new string value";
// Console.WriteLine
}
}
public static class MyClass
{
public void MapReduceTest()
{
var words = new[] {"...some text goes here..."};
var wordOccurrences = words
.GroupBy(w => w)
.Select(intermediate => new
{
Word = intermediate.Key,
Frequency = intermediate.Sum(w => 1)
})
.Where(w => w.Frequency > 10)
.OrderBy(w => w.Frequency);
}
}
public void MapReduceTest()
{
string[] words = new string[]
{
"...some text goes here..."
};
var wordOccurrences =
from w in words
group w by w
into intermediate
select new
{
Word = intermediate.Key,
Frequency = intermediate.Sum((string w) => 1)
}
into w
where w.Frequency > 10
orderby w.Frequency
select w;
}
new
{
Word = intermediate.Key,
Frequency = intermediate.Sum(w => 1)
}
public void MapReduceTest()
{
string[] words = new string[] { "...some text goes here..." };
var wordOccurrences = Enumerable.OrderBy(Enumerable.Where(Enumerable.Select(Enumerable.GroupBy<string, string>(words, delegate (string w) {
return w;
}), delegate (IGrouping<string, string> intermediate) {
return new { Word = intermediate.Key, Frequency = Enumerable.Sum<string>(intermediate, (Func<string, int>) (w => 1)) };
}), delegate (<>f__AnonymousType0<string, int> w) {
return w.Frequency > 10;
}), delegate (<>f__AnonymousType0<string, int> w) {
return w.Frequency;
});
}
Source: https://habr.com/ru/post/145932/
All Articles