C#3.0的自动属性是否完全取代了归档?
我的意思是,我可以直接使用该属性而不是归档作为属性作为私人支持字段.(对不起,我只是这样理解).
int a;
public int A
{
get;set;
}
Run Code Online (Sandbox Code Playgroud) 我试图在Generics上应用运算符(对于我的例子,乘法)
public static List<TOutput> Conversion<TOutput>(List<TInput> input)
{
List<TOutput> outList = new List<TOutput>();
foreach(TInput tinput in input)
{
double dbl = tinput *tinput;
outList.Add(dbl);
}
return outList;
}
Run Code Online (Sandbox Code Playgroud)
修复它的任何解决方法?
从给定的字符串
(即)
string str = "dry sky one two try";
var nonVowels = str.Split(' ').Where(x => !x.Contains("aeiou")); (not working).
Run Code Online (Sandbox Code Playgroud)
我怎样才能提取非元音词?
强制执行通用约束时
class GenericTest
{
public void Sample<T>(T someValue) where T:Racer,new()
{
Console.WriteLine(someValue.Car);
}
}
Run Code Online (Sandbox Code Playgroud)
Type T应该来自Base Type Racer(如果有什么不对的话,纠正我).
public class Racer
{
string name;
string car;
public Racer() { }
public Racer(string name, string car)
{
this.name = name;
this.car = car;
}
public string Name
{
get { return name; }
}
public string Car
{
get { return car; }
}
}
Run Code Online (Sandbox Code Playgroud)
在"Main()"中我执行为
static void Main(string[] args)
{
List<Racer> rcr = new List<Racer>();
rcr.Add(new Racer("James","Ferrari"));
rcr.Add(new …Run Code Online (Sandbox Code Playgroud) 我从Jon Skeet的"C#深度"中得到了这个.
他提到以下内容是有效的
(1) class Sample<T> where T:class,Stream
Run Code Online (Sandbox Code Playgroud)
以下是无效的
(2) class Sample<T> where T:Stream,class
Run Code Online (Sandbox Code Playgroud)
第二个无效的原因是什么?
我是C#的新手.我想知道使用Collections的不同之处.我怀疑,之前可能会问以下问题(如果这样,请告诉我链接).
有什么区别
IList<int> intCollection = new List<int>();
Run Code Online (Sandbox Code Playgroud)
和
List<int> intCollection = new List<int>();
Run Code Online (Sandbox Code Playgroud)
当我宣布
string x = new string(new char[0]);
Run Code Online (Sandbox Code Playgroud)
它运作正常.我的问题是x将分配什么值?
当我检查
Console.WriteLine(x.CompareTo(null)==0);,it returns false.
Run Code Online (Sandbox Code Playgroud) 1)当我有
Static void Sample<T>(T a,T b)
Run Code Online (Sandbox Code Playgroud)
声明Sample是否强制所有参数都必须是T类型?
2)Static void Sample(T a,T b)除非我指明,否则声明不是通用方法
Sample<T>吗?
我正在学习lambda表达式和委托.虽然我尝试执行以下操作,但我在标记为粗线的行处收到错误.(错误:运算符'+ ='不能应用于'Test.MessageDelegate'和'lambda expression'类型的操作数.)帮我处理lambda表达式.
namespace Test
{
public delegate void MessageDelegate(string title,object sender,EventArgs e);
class Program
{
static event MessageDelegate logEvent;
static void Main(string[] args)
{
logEvent = new MessageDelegate(OnLog);
logEvent("title",Program.logEvent,EventArgs.Empty);
Run Code Online (Sandbox Code Playgroud)
logEvent + =(src,e)=> {OnLog("Some",src,e); };
Console.ReadKey(true);
}
static void OnLog(string title, object sender, EventArgs e)
{
if (logEvent != null)
{
Console.WriteLine("title={0}", title);
Console.WriteLine("sender={0}", sender);
Console.WriteLine("arguments={0}",e.GetType());
}
}
}
}
Run Code Online (Sandbox Code Playgroud)