C# 算术运算导致整数溢出
使用C获取云firestore用户/email/(key:values)的数据# 我尝试使用电子邮件文本框(即TboxEmail)通过C# 算术运算导致整数溢出,c#,visual-studio,firebase,google-cloud-firestore,C#,Visual Studio,Firebase,Google Cloud Firestore,使用C获取云firestore用户/email/(key:values)的数据# 我尝试使用电子邮件文本框(即TboxEmail)通过 DocumentReference docref = Data.Collection("users").Document(TboxEmail.Text); DocumentSnapshot snap = await docref.GetSnapshotAsync(); 我创建了一个Userinfo类,它获取所有数据并只选择所需的key:va
DocumentReference docref = Data.Collection("users").Document(TboxEmail.Text);
DocumentSnapshot snap = await docref.GetSnapshotAsync();
我创建了一个Userinfo类,它获取所有数据并只选择所需的key:value
using Google.Cloud.Firestore;
namespace FormApp
{
[FirestoreData]
class Userinfo
{
[FirestoreProperty]
public string email { get; set; }
[FirestoreProperty]
public bool status { get; set; }
[FirestoreProperty]
public string name { get; set; }
[FirestoreProperty]
public string address { get; set; }
[FirestoreProperty]
public int phone { get; set; }
}
}
密码
bool s;
try
{
DocumentReference docref = Data.Collection("users").Document(TboxEmail.Text);
DocumentSnapshot snap = await docref.GetSnapshotAsync();
if (snap.Exists)
{
Userinfo userinfo = snap.ConvertTo<Userinfo>();
s = userinfo.status;
if (s)
{
this.Hide();
Dashboard home = new Dashboard(TboxEmail.Text);
home.ShowDialog();
return;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Show(ex.StackTrace);
}
ex.StackTrace的异常为
很难猜测确切的细节,但异常提示整数有问题。大多数电话号码都超过了
int
数据类型的大小,所以我会看一下。解决方案是将电话号码存储为字符串,这样您也可以表示国家代码(如+1),而不必担心整数精度。很难猜测确切的细节,但异常提示整数有问题。大多数电话号码都超过了int
数据类型的大小,所以我会看一下。解决方案是将电话号码存储为字符串,这样您也可以表示国家代码(如+1),而不必担心整数精度。将int转换为Int64 for phone解决了这个问题
using Google.Cloud.Firestore;
namespace FormApp
{
[FirestoreData]
class Userinfo
{
[FirestoreProperty]
public string email { get; set; }
.....
[FirestoreProperty]
public Int64 phone { get; set; }
}
}
将int转换为Int64用于phone解决了这个问题
using Google.Cloud.Firestore;
namespace FormApp
{
[FirestoreData]
class Userinfo
{
[FirestoreProperty]
public string email { get; set; }
.....
[FirestoreProperty]
public Int64 phone { get; set; }
}
}
“那么上面的代码无法转换userinfo中的数据”-如果它没有引发异常,那么它怎么会失败?是返回
userInfo==null
还是email
属性null
或空字符串“
-还是其他什么?“算术运算导致溢出”是异常@DaiPost该异常的全部详细信息,包括消息
和堆栈跟踪
,并对每个内部异常
执行相同的操作。我是新来的,我已经发布了我的完整代码@Dai您能帮我吗?使用调试器检查catch
块中的ex
。“那么上面的代码无法转换userinfo中的数据”-如果它没有引发异常,那么它怎么会失败?是返回userInfo==null
还是email
属性null
或空字符串“
-还是其他什么?“算术运算导致溢出”是异常@DaiPost该异常的全部详细信息,包括消息
和堆栈跟踪
,并对每个内部异常
执行相同的操作。我是新来的,我已经发布了我的完整代码@Dai你能帮我吗?使用调试器检查catch
块内的ex
。电话号码是字符串,而不是整数-因为前导零在许多地方都很重要,并且你不能使用整数或扩展名或字母数字正确表示E.164数字。电话号码是字符串,反正不是整数-因为前导零在很多地方都很重要,并且您不能使用整数、分机号或字母数字正确表示E.164数字。您仍然不应该将电话号码存储为整数值,您应该使用字符串
。电话号码不是整数!您仍然不应该将电话号码存储为整数值,您应该使用字符串
。电话号码不是整数!