[UWP]整数比较 - localsettings和JToken [英] [UWP]Comparison of Integers - localsettings and JToken

查看:67
本文介绍了[UWP]整数比较 - localsettings和JToken的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下事项:

Windows UWP App - 一个功能是将JSON源解析为日历项 - 所有工作

Windows UWP App - one function is to parse a JSON source into calendar items - all working

想要介绍当新日历项目进入时给出吐司通知的功能

Looking to introduce function where toast notification is given when a new calendar item comes in

日历项目包含一个整数的ID字段并充当记录ID

The calendar items contain an ID field that is an integer and acts as a record ID

确认向此日历添加项目会增加ID,它实际上是唯一的记录ID

Confirmed that adding items to this calendar increases the ID, it is essentially the unique record ID

因此,想要跟踪日历ID并将其存储在本地设置中,所以我知道应用程序上次运行时的最高记录ID是多少。 无法真正进行日期时间比较,因为事实是可能会有一个新项目进入最后一个最高日期值小于
,并且它不会触发通知。 无论日程安排如何,都会有一个新项目进入。

So, want to track the Calendar ID and store it in a localsetting, so I know what the highest Record ID is from the last time the app ran.  Can't really do Date Time comparison, because the fact is there could be a new item coming in that is less than the last highest Date value, and it would not trigger a notification.  The idea is that a new Item has come in, regardless of date scheduled.

想要将该值与传入记录进行比较,并且当记录带有更高的ID值时,触发一个表示新项目的toast通知。

Want to compare that value to incoming records, and when a record comes in with a higher ID value, trigger a toast notification that indicates a new item.

这将作为后台任务的基础

This would serve as the basis for a background task

主要问题是对传入进行比较ID值为当前的localsettings值。

The major problem is running a comparison on the incoming ID value to the current localsettings value.

if(Int32.Parse(itemResult._id)> Int32.Parse((string)localSettings.Values [" lastgenevent"]))

if (Int32.Parse(itemResult._id) > Int32.Parse((string)localSettings.Values["lastgenevent"]))

无论我如何对上述陈述进行分割,我都会得到Cast Exception或Null Exception。 我无法弄清楚如何编写上述语句来对两个值进行整数比较,这将导致在遇到更高的
int值时准确跟踪。

No matter how I slice the above statement, I either get a Cast Exception or a Null Exception.  I cannot figure out how to write the above statement to make an integer comparison of the two values that will result in accurately tracking when a higher int value is encountered.

任何帮助我们将非常感谢。

Any help would be sincerely appreciated.

谢谢

DWM

推荐答案

恐怕任何人都很难告诉你具体数据是怎么样的看过它也没有访问它但你可以使用Int32.TryParse方法尝试将字符串解析为int而不会得到异常。你应该
也检查你正在使用的引用实际上是指内存中的实际对象。这样的事情:

I am afraid it will be very hard for anyone to tell you how your specific data look like without having seen it nor have access to it but you could use the Int32.TryParse method to try to parse a string to an int without getting an exception. You should also check that the references you are using actually refers to an actual object in memory. Something like this:

int id = 0;
            int lastgenevent = 0;
            if (itemResult != null && Int32.TryParse(itemResult._id, out id)
                && localSettings != null && localSettings.Values != null && localSettings.Values.ContainsKey("lastgenevent")
                && Int32.TryParse(localSettings.Values["lastgenevent"].ToString(), out lastgenevent)
                && id > lastgenevent)
            { 
  //...
            }

希望有所帮助。

请记住通过将有用的帖子标记为答案来关闭您的主题,如果您有新问题,请启动新主题。请不要在同一个帖子中提出几个问题。

Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.


这篇关于[UWP]整数比较 - localsettings和JToken的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆