草庐IT

non_empty

全部标签

c# - 为什么 Enumerable.Empty() 返回一个空数组?

我希望Enumerable.Empty()的实现是这样的:publicstaticIEnumerableEmpty(){yieldbreak;}但是实现是这样的:publicstaticIEnumerableEmpty(){returnEmptyEnumerable.Instance;}internalclassEmptyEnumerable{privatestaticvolatileTElement[]instance;publicstaticIEnumerableInstance{get{if(EmptyEnumerable.instance==null)EmptyEnumerab

c# - 没有什么等于 String.Empty,null 不等于 String.Empty,我在这里缺少什么?

在混合代码项目(VB和C#)中,我们正在调试一些旧的VisualBasic代码,如下所示:IfRequest.Params("xxx")""Then'dosomething我认为这是一个错误,因为Request.Params可能是null,在这种情况下,语句会变成false,这不是我的想法。我是这么想的。我刚刚再次发现VB的Nothing和C#的null不是一回事,Nothing也不一样作为null。事实上:if(String.Empty==null)//inC#thisisalwaysfalse(correct)IfString.Empty=NothingThen'inVBthisi

c# - 数字必杀技 : Where does a callvirt of a non-existent method end up?

我在其基类中标记为抽象的库类上调用属性集访问器。现在在运行时我force应用程序针对另一个版本的库运行,其中类仅实现基类的底层接口(interface),但不是从它派生的。有趣的是,.NET将运行代码,但设置该属性没有任何效果。幕后发生了什么?违规代码:MyDbParameterparam=newMyDbParameter();param.ParameterName="p";Console.Out.WriteLine("ParameterName:"+param.ParameterName);库2.0(已编译)publicsealedclassMyDbParameter:System.

c# - 为什么此 XAML 收到错误 : Items collection must be empty before using ItemsSource

任何人都可以从这段代码中联想到为什么ItemsSource行会得到一个ItemscollectionmustbeemptybeforeusingItemsSource.错误?我发现的大多数解决方案都指向错误组合的XAML,例如我似乎没有的额外元素等。当我拿出来的时候ItemsSource="{BindingCustomers}"它运行没有错误(但当然不会显示我的客户列表)。Customers在ViewModel中这样定义,其中有3个CustomerViewModels:Customer[]customers=Customer.GetCustomers();IEnumerablecust

c# - Lazy<T> 延迟加载错误 : A field initializer cannot reference the non-static field, 方法或属性

我第一次尝试使用延迟加载来初始化我的类中的进度对象。但是,我收到以下错误:Afieldinitializercannotreferencethenon-staticfield,method,orproperty.privateLazym_progress=newLazy(()=>{longtotalBytes=m_transferManager.TotalSize();returnnewProgress(totalBytes);});在.NET2.0中,我可以执行以下操作,但我更愿意使用更新的方法:privateProgressm_progress;privateProgressPro

c# - "The request failed with an empty response"调用网络服务时

当从aspx页面调用托管在服务器中的网络服务时,我收到类似“请求失败,响应为空”的错误。我页面中的代码try{HttpWebRequestrequest1=(HttpWebRequest)WebRequest.Create("https://login.erp.com/rodeprovisioning/provisioning.asmx");request1.Accept="text/xml";request1.Method="POST";WebProxyproxyObject=newSystem.Net.WebProxy("http://10.0.0.1:8080/",true);r

c# - LINQ to SQL insert-if-non-existent

我想知道是否有更简单的方法来插入表中尚不存在的记录。我仍在努力培养我的LINQtoSQL技能。这是我得到的,但似乎应该有更简单的方法。publicstaticTEntityInsertIfNotExists(DataContextdb,Tabletable,Funcwhere,TEntityrecord)whereTEntity:class{TEntityexisting=table.SingleOrDefault(where);if(existing!=null){returnexisting;}else{table.InsertOnSubmit(record);//Can'tuse

c# - "Data Source cannot be empty. Use :memory: to open an in-memory database"是什么意思?

我最近将我的SQLServer数据库转换为SQLite数据库。但是当我尝试使用.Open()打开我的SQLite时,它​​抛出了这个错误:DataSourcecannotbeempty.Use:memory:toopenanin-memorydatabase编辑:添加连接字符串:ConnectionString=@"DataSource=D:\XXX.db;Version=3";connection=newSQLiteConnection(connectionString);connection.Open();为什么我会得到这个?我将相同的SQLServer数据库转换为SQLCE和my

c# - The non-generic method cannot be used with type arguments in this context 是什么意思?

我有以下类和方法:publicclassUserManager:IDisposablewhereTUser:class,global::Microsoft.AspNet.Identity.IUserwhereTKey:global::System.IEquatable{publicvirtualTaskFindByIdAsync(TKeyuserId);和:privateApplicationUserManager_userManager;publicApplicationUserManagerUserManager{get{return_userManager??Request.Ge

c# - Entity Framework : Alternate solution to using non primary unique keys in an association

我知道EntityFramework不允许您使用非主唯一键作为外键关联从数据库生成模型。我可以手动修改EDMX吗?如果是这样,有人可以给我一个例子或引用吗?如果不是,还有其他可能吗?最简单的例子:这是表的DDL。您会注意到我有一个从PersonType.TypeCode到Person.TypeCode的外键CREATETABLE[dbo].[PersonType]([PersonTypeId][int]NOTNULL,[TypeCode][varchar](10)NOTNULL,[TypeDesc][varchar](max)NULL,CONSTRAINT[PK_PersonType]