Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 算术运算导致整数溢出_C#_Visual Studio_Firebase_Google Cloud Firestore - Fatal编程技术网

C# 算术运算导致整数溢出

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

使用C获取云firestore用户/email/(key:values)的数据#

我尝试使用电子邮件文本框(即TboxEmail)通过

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数字。您仍然不应该将电话号码存储为整数值,您应该使用
字符串
。电话号码不是整数!您仍然不应该将电话号码存储为整数值,您应该使用
字符串
。电话号码不是整数!