如何删除ObservableCollection<Customer>
Class Customer中的重复项有a string Name,string PhoneNumber
如果我Name = Jonh在第一时间添加- 好的
在第二个Name = Jonh(重复)<--------------------我希望删除重复的项目.
(删除重复的名称,不删除PhoneNumber)
我是新手Tasks,仍在努力掌握这一概念.
虽然做了一些研究,我碰到这个文章与下面的代码:
Task<int32> t = new Task<int32>(n => Sum((Int32)n), 1000);
Run Code Online (Sandbox Code Playgroud)
从示例中,我了解到它1000是作为Sum函数的参数传递的,但我似乎并不理解语法.
我的问题是编译器如何知道它应该取代n与1000当总和被称为?
我有一个字符串:string s ="My Favorite numbers are: 42, 0x42, 24 and 0x24"
有没有办法使用正则表达式将所有十六进制数替换为它们的十进制表示?
对于上面的例子,我希望得到:"My Favorite numbers are: 42, 66, 24 and 36".
我遇到了编译器这个有趣的行为:
如果我有
public int GetInt()
{
Random rnd = new Random();
double d = rnd.NextDouble();
int i = d % 1000;
return i;
}
Run Code Online (Sandbox Code Playgroud)
我得到一个错误:
Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)
这实际上有意义的,因为1000可以是一个double,而结果modulo操作可能是double为好.
但在将代码更改为:
public int GetInt()
{
Random rnd = new Random();
double d = rnd.NextDouble();
int i = d % (int)1000;
return i;
}
Run Code Online (Sandbox Code Playgroud)
错误仍然存在.
据我所知,编译器拥有所有信息,以确定modulo运算符的输出将是一个int,所以为什么不编译?
我知道我们可以使用构造函数链从其他构造函数调用参数化构造函数.
但,
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello, world!");
var t1 = new T1("t2");
}
}
public class T1
{
public T1()
{
Console.WriteLine("t1");
}
public T1(string s):base()
{
Console.WriteLine(s);
}
}
Run Code Online (Sandbox Code Playgroud)
这似乎没有调用基础构造函数(没有任何参数).
有任何想法吗 ?
编辑:
当前:打印t2.t1不在控制台上.
所以,我采用了以下方法:
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello, world!");
var t1 = new T1("t2");
}
}
public class T1
{
private void privateMethod()
{
Console.WriteLine("common method");
}
public T1()
{
privateMethod();
}
public T1(string …Run Code Online (Sandbox Code Playgroud)