这可能是我花了好几个小时解决很长时间的最大浪费时间问题.
var db = new hublisherEntities();
establishment_brands est = new establishment_brands();
est.brand_id = 1;
est.establishment_id = 1;
est.price = collection["price"];
est.size = collection["size"];
db.establishment_brands.Add(est);
db.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
这给了我一个错误
值不能为空.参数名称:source
堆栈跟踪
[ArgumentNullException:Value不能为null.参数名称:source] System.Linq.Enumerable.Any(IEnumerable
1 source, Func2 predicate)+4083335 System.Data.Entity.Internal.InternalContext.WrapUpdateException(UpdateException updateException)+87
System.Data.Entity.Internal.InternalContext.SaveChanges()+ 193
System.Data.Entity.Internal.LazyInternalContext.SaveChanges()+ 33
System.Data.Entity.DbContext.SaveChanges()+20 ......
我只想在表中添加一个实体.ORM是EF.
我正在进行一些单元测试,我想知道是否有任何方法可以测试列表是否按其包含的对象的属性排序.
现在我这样做,但我不喜欢它,我想要一个更好的方法.有人可以帮帮我吗?
// (fill the list)
List<StudyFeedItem> studyFeeds =
Feeds.GetStudyFeeds(2120, DateTime.Today.AddDays(-200), 20);
StudyFeedItem previous = studyFeeds.First();
foreach (StudyFeedItem item in studyFeeds)
{
if (item != previous)
{
Assert.IsTrue(previous.Date > item.Date);
}
previous = item;
}
Run Code Online (Sandbox Code Playgroud) 我有一个包含以下两个属性的类:
public int Id { get; private set; }
public T[] Values { get; private set; }
Run Code Online (Sandbox Code Playgroud)
我做了它IEquatable<T>并覆盖了object.Equals这样的:
public override bool Equals(object obj)
{
return Equals(obj as SimpleTableRow<T>);
}
public bool Equals(SimpleTableRow<T> other)
{
// Check for null
if(ReferenceEquals(other, null))
return false;
// Check for same reference
if(ReferenceEquals(this, other))
return true;
// Check for same Id and same Values
return Id == other.Id && Values.SequenceEqual(other.Values);
}
Run Code Online (Sandbox Code Playgroud)
当object.Equals我有覆盖时,我GetHashCode当然也必须覆盖.但是我应该实现什么代码?如何从通用数组中创建哈希码?我如何将它与Id整数相结合?
public override int …Run Code Online (Sandbox Code Playgroud) 创建一个控制台应用程序来重现:
struct Test
{
public static readonly Test? Null = null;
}
class Program
{
static void Main(string[] args)
{
var t = Test.Null;
}
}
Run Code Online (Sandbox Code Playgroud)
它是可编译的,但我们将在运行时具有以下内容:
mscorlib.dll中发生了未处理的"System.TypeLoadException"类型异常.附加信息:无法从程序集"ConsoleApplication17,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null"加载类型"ConsoleApplication17.Test".
这种方法解决了这个问题:
struct Test
{
public static Test? Null => null;
}
Run Code Online (Sandbox Code Playgroud) 我今天正在进行一些代码审查,并遇到了一些开发人员编写的旧代码.它就是这样的
public abstract class BaseControl
{
internal abstract void DoSomething();
}
Run Code Online (Sandbox Code Playgroud)
如果在同一个程序集中有派生类,它就可以工作
public class DerivedControl : BaseControl
{
internal override void DoSomething()
{
}
}
Run Code Online (Sandbox Code Playgroud)
但是在不同的程序集中派生基类会产生编译时错误
DerivedControl does not implement inherited abstract member 'BaseControl.DoSomething()
Run Code Online (Sandbox Code Playgroud)
这让我思考.为什么有人会将方法声明为内部抽象?
是否有任何tryparse Convert.FromBase64String
或我们只计算字符是否等于64个字符.
我复制加密和解密类,但以下行有错误.我想检查是否cipherText可以无错误地转换
byte[] bytes = Convert.FromBase64String(cipherText);
Run Code Online (Sandbox Code Playgroud) 在我开始之前,我想说我已经用谷歌搜索了这个问题的解决方案,但要么不理解它们(我是新手)或者它们不起作用.
我想要做的是将JSON数据发送到localhost:8000上的REST API,格式如下:
{
"username" : "myusername",
"password" : "mypass"
}
Run Code Online (Sandbox Code Playgroud)
然后,我期望一个包含字符串标记的响应,如下所示,
{
"token" : "rgh2ghgdsfds"
}
Run Code Online (Sandbox Code Playgroud)
如何发送json数据然后从响应中解析令牌?我已经看到了这样做的同步方法,但由于某种原因,它们不起作用(或者仅仅因为我不知道它在哪个命名空间).如果您采用异步方式执行此操作,请告诉我它是如何工作的?
提前致谢.
我正在使用swift为iOS 9.3编写应用程序,需要一张地图来显示用户位置.我初始化CLLocationManager及其委托,我配置info.plist 隐私 - 位置使用说明字符串并调用requestWhenInUseAuthorization但它不显示任何授权请求.
这是我的代码:
import UIKit
import MapKit
class DetailController: UIViewController, CLLocationManagerDelegate {
var locManager: CLLocationManager!
@IBOutlet var myMap: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
mostraPosizione()
}
func mostraPosizione(){
locManager = CLLocationManager()
locManager.delegate = self
locManager.desiredAccuracy = kCLLocationAccuracyBest
let authorizationStatus = CLLocationManager.authorizationStatus()
if (authorizationStatus == CLAuthorizationStatus.NotDetermined) {
locManager.requestWhenInUseAuthorization()
} else {
locManager.startUpdatingLocation()
}
myMap.showsUserLocation = true
}
func locManager(manager: CLLocationManager,
didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if (status == CLAuthorizationStatus.NotDetermined) {
locManager.requestWhenInUseAuthorization()
} else { …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Process对象打印PDF文件.在某种程度上,我可以成功打印它.但现在我想设置打印机属性..比如没有副本,纸张大小等.但我没有看到任何属性来设置这些值.我正在使用以下代码来打印PDF
string fileName = "";
string arguments = "";
string verbToUse = "";
int i = 0;
ProcessStartInfo startInfo = new ProcessStartInfo();
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "pdf files (*.pdf)|*.pdf|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((fileName = openFileDialog1.FileName) != null)
{
startInfo = new ProcessStartInfo(fileName);
if (File.Exists(fileName))
{
i = 0;
foreach (String verb in startInfo.Verbs)
{
// Display the possible verbs.
MessageBox.Show(i.ToString() + ". " …Run Code Online (Sandbox Code Playgroud) 我正在试图找出最佳方法来确定是否以string4个数字结束.号码范围是0000-9999.
例如.我有一个字符串,可以是"MVI_2546"或类似"FILETEST".
我需要解析该字符串并基本上返回一个true或false值,具体取决于它是否以4个数字结束.
c# ×8
.net ×1
arrays ×1
asp.net-mvc ×1
generics ×1
hashcode ×1
html-lists ×1
inheritance ×1
list ×1
location ×1
nullable ×1
numbers ×1
overriding ×1
pdf ×1
printing ×1
properties ×1
regex ×1
struct ×1
swift ×1
unit-testing ×1
xamarin ×1