我已经读过.NET支持返回引用,但C#没有.有特殊原因吗?为什么我不能做这样的事情:
static ref int Max(ref int x, ref int y)
{
if (x > y)
return ref x;
else
return ref y;
}
Run Code Online (Sandbox Code Playgroud) 是否可以在C#代码文件中添加文字XML数据?我目前正在使用多行字符串文字,但你可以看到它变得混乱.有没有更好的方法呢?
string XML = @"<?xml version=""1.0"" encoding=""utf-8""?>
<customUI xmlns=""http://schemas.example.com/customui"">
<toolbar id=""save"">
</toolbar>
</customUI>";
Run Code Online (Sandbox Code Playgroud) 出于好奇,再一次:
在VB.Net中编写了几个项目后,我惊讶地发现C#和VB.NET LINQ用法之间存在一些细微差别.例如,如果我们想要按多个属性(列)对元素进行分组,我们需要显式创建一个新的匿名类型:
var procs = from c in Process.GetProcesses()
group c by new {c.BasePriority, c.Id} into d
select d;
Run Code Online (Sandbox Code Playgroud)
而在VB.NET中,更直接的语法已经做到了:
Dim b = From c In Process.GetProcesses()
Group c By c.BasePriority, c.Id Into Group
Select Group
Run Code Online (Sandbox Code Playgroud)
因此,不需要在这里创建一个带有"new"的类型.
还有什么区别?C#和VB.NET中的LINQ语法有什么好的比较吗?
c# ×3
.net ×1
c#-to-vb.net ×1
linq ×1
literals ×1
reference ×1
return-type ×1
vb.net ×1
xml ×1