有时候检查对象是否不是X的类型是有道理的,所以你需要这样做:
if(this.GetType() != typeof(X))
{
//Do my thing.
}
Run Code Online (Sandbox Code Playgroud)
这对我来说有点麻烦,不会有这样的东西更好:
if(this is not X)
{
//Do my thing
}
Run Code Online (Sandbox Code Playgroud) 有没有办法使用一种类似C#的函数out或ref参数修饰符与Javascript来做这样的事情:
function myManyReturnFunction(number1, number2, out x, out y) {
x = number1 * number2;
y = number1 / number2;
return true;
}
var height1, height2 = 0;
var check = myManyReturnFunction(1,1, out height1, out hight2);
Run Code Online (Sandbox Code Playgroud)
我也想改变变量的引用.所以是的,通过引用传递参数.
我有一个简单的表:
ID | 值
当我这样做:
var sequence = from c in valuesVault.GetTable()
select new {RandomIDX = Guid.NewGuid(), c.ID, c.Value};
Run Code Online (Sandbox Code Playgroud)
投影中的每个元素都具有相同guid的值...我如何编写这个以便为投影中的每个元素获得不同的随机guid值?
编辑
澄清这个问题.该GetTable()方法仅调用此:
return this.context.GetTable<T>();
Run Code Online (Sandbox Code Playgroud)
其中this.contenxt是类型为T的DataContext.
itteration完成,因为它总是完成,没有什么花哨的:
foreach (var c in seq)
{
Trace.WriteLine(c.RandomIDX + " " + c.Value);
}
Run Code Online (Sandbox Code Playgroud)
输出:
bf59c94e-119c-4eaf-a0d5-3bb91699b04d What is/was your mother's maiden name?
bf59c94e-119c-4eaf-a0d5-3bb91699b04d What was the last name of one of your high school English teachers?
bf59c94e-119c-4eaf-a0d5-3bb91699b04d In elementary school, what was your best friend's first and last name?
Run Code Online (Sandbox Code Playgroud)
编辑2 使用linq2Sql提供程序框.我在它周围构建了一些泛型包装器,但它们不会改变代码中的IQuaryable或IEnumerable函数的方式.
如果我的列表位于此处:
http://sharepoint2010m/Lists/VideoPlayerData/AllItems.aspx
Run Code Online (Sandbox Code Playgroud)
如何通过o-data服务获得实际项目?
好吧,当我在构建一个自定义枚举器时,我注意到了这种与收益率有关的行为
说你有这样的事情:
public class EnumeratorExample
{
public static IEnumerable<int> GetSource(int startPoint)
{
int[] values = new int[]{1,2,3,4,5,6,7};
Contract.Invariant(startPoint < values.Length);
bool keepSearching = true;
int index = startPoint;
while(keepSearching)
{
yield return values[index];
//The mind reels here
index ++
keepSearching = index < values.Length;
}
}
}
Run Code Online (Sandbox Code Playgroud)
在技术上从函数返回之后,是什么让编译器的底层可以执行索引++和while循环中的其余代码?
无论我试图抛出什么,这里的方法总会导致以下异常:
var retVal = this.DirectoryEntry.Invoke("ChangePassword", new object[] { oldPassword, newPassword }) == null;
Run Code Online (Sandbox Code Playgroud)
InnerException = {"密码不符合密码策略要求.检查最小密码长度,密码复杂性和密码历史记录要求.(HRESULT异常:0x800708C5)"}
我自然检查了域默认策略(在我的测试域中找不到),OU组策略(不存在)并且找不到任何可以控制密码策略的内容,但无论我提供给函数的密码有多长或多复杂,它会导致相同的异常. 现在最有趣的部分 是当我做同样的事情(对于相同的DirectoryEntity对象和相同的密码),通过调用:
var retVal = this.DirectoryEntry.Invoke("SetPassword", new object[] { newPassword }) == null;
Run Code Online (Sandbox Code Playgroud)
最后一次通话没有任何问题.
因此,c#已经发展为静态类型语言,并且在利用.net框架开发业务线应用程序方面做了一个非常完美的工作.
现在,显然,在最近的过去,微软已经开始实现其他基本范式的飞跃,而c#和.net从未真正声称是最近的工具.
其中之一是DLR
好的语言多样性 - 很棒,我在想,现在看来我必须改变我的思维方式当我用类编写我的业务实体时,如果我想利用这个功能......这很酷,我我都在学习新的东西.但在此之前,我在这方面对受尊敬的社区提出了一些问题.现在为了澄清,我对DLR和CLR的应用更感兴趣.
所以我们开始:
您认为,DLR是否是一个可行的功能,从企业商业软件开发的角度来看是否值得关注?这意味着,c#真的需要它作为一个功能来继续做它正在做的事情,还是在那时切换到一个标准的动态类型语言更有意义?
在CLR和DLR的开发和编写代码的组合在业务适用性方面如何发挥作用?具体的例子对我来说是最有价值的.
优点.
现在msdn说:
Provides Future Benefits of the DLR and .NET Framework
Languages implemented by using the DLR can benefit from future DLR and .NET Framework improvements. For example, if the .NET Framework releases a new version that has an improved garbage collector or faster assembly loading time, languages implemented by using the DLR immediately get the same benefit. If the DLR adds optimizations such as better compilation, the performance also …
我试图避免在我的生产代码中使用静态类,因为它们无法注入,无法控制默认初始化,最后你无法隐式清理资源,因为没有静态对象的析构函数.另外,你也不能为静态类实现IDisposable,所以听起来像静态类永远不适合作为非托管资源的包装......完全看起来单例是一种更好的解决方案来直接替换静态类的使用那种情况.但我的问题是 - 为什么编译器不支持静态破坏,毕竟GC会跟踪对静态对象和实例的引用有什么区别呢?
我正在尝试简化将数据从WebMethod层返回到客户端的过程,并表示来自客户端的参数集,Dictionary<string,string>以执行以下操作:
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static override ResultObject<List<PatientInfo>> GetResults(Dictionary<string, string> query)
{
ResultObject<List<PatientInfo>> resultObject = null;
if (!query.ContainsKey("finValue"))
{
resultObject = new ResultObject<List<PatientInfo>>("Missing finValue parameter from the query");
}
string finValue = query["finValue"];
if(finValue == null)
{
resultObject = new ResultObject<List<PatientInfo>>("Missing finValue parameter value from the query");
}
var patientData = GetPatientsByFin(finValue);
resultObject = new ResultObject<List<PatientInfo>>(patientData);
return resultObject;
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:如何传递和反序列化Dictionary参数?
.net ×4
c# ×4
.net-4.0 ×1
c#-4.0 ×1
clr ×1
enumerable ×1
enumeration ×1
guid ×1
javascript ×1
jquery ×1
json ×1
keyword ×1
linq ×1
list ×1
odata ×1
sql ×1
sql-server ×1
static ×1
types ×1
wcf ×1
webmethod ×1
yield ×1
yield-return ×1