小编mas*_*rur的帖子

C#方法在匿名类型中初始化

我正在浏览Sam的LINQ Unleashed for C#,并在第7页列出:

匿名类型可以初始化为包含方法,但这些可能只是语言学家感兴趣的.

我真的不明白语言学家的评论是否是一个笑话.无论如何,可以在C#中做这样的事情

var obj = new { 
    Name = "Joe", Weight = 200,
    GetAge = new Func<int>(() => { return 43; })
};
Run Code Online (Sandbox Code Playgroud)

有没有人有真实生活情况需要在匿名类型中定义一个函数?或者这只是类型推理的结果而没有实际应用?

c# linq lambda anonymous-types

10
推荐指数
1
解决办法
1219
查看次数

iBeacons - 公司(Estimote,Gimbal等)SDKs与Android/iOS库

我一直在用他们的Android SDK玩Estimote iBeacons.但是,我仍然对为什么有这么多SDK可用而感到困惑.

iBeacons只是标准的蓝牙设备,具有蓝牙低功耗(BLE)蓝牙4.0规范的一部分.只要您拥有"Bluetooth Smart Ready"设备(iPhone 4S +和Android 4.3+),您就能够检测到所有iBeacons,无论信标制造商如何.Android(蓝牙低功耗连接)和iPhone(iOS开发者库)都提供系统级库来开发应用程序以使用iBeacons.

那么为什么有这么多的SDK用于连接到iBeacons(Gimbal,Estimote,Radius Networks,开源Android API).

所以我有几个问题:

  • 为什么有这么多SDK可用?制造商可以锁定他们的信标只能通过他们的SDK访问吗?

  • 在可Android 4.3的蓝牙连接库调查,并找到任何iBeacon显示?

  • 使用非Android SDK有什么好处?在我看来,只有android库可以实现地理围栏和接近检测,但通知和持续的背景轮询是不可能的.

android bluetooth ios ibeacon ibeacon-android

7
推荐指数
1
解决办法
1839
查看次数

Android AltBeacon后台服务测距

我正在使用AltBeacon库开发蓝牙应用程序.似乎BeaconManager每个应用程序只允许实例.我面临的问题是:我想要一个持续运行的后台服务,不断进行蓝牙测距并发送通知.如果我打开我的应用程序(将它带到前台)我就是暂停范围的服务.然后,前台活动将进行测距并在屏幕上显示内容.

问题是BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);活动和服务中的信标管理器(来自)是同一个实例.因此,当活动关闭时,beaconManager.unbind(this);将被调用并且服务中的范围通知程序不再触发.

是否有可能获得两个独立的信标管理器实例?如果没有,我如何在连续运行的服务和活动中进行测距?

RangingActivity

@Override
protected void onCreate(Bundle savedInstanceState) {
...
regionEstimote = new Region("estimote", null, null, null);
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.bind(this);
}
@Override
protected void onDestroy() {
    super.onDestroy();
    notificationManager.cancel(NOTIFICATION_ID);
    //beaconManager.unbind(this);
}
@Override
public void onBeaconServiceConnect() {
    beaconManager.setRangeNotifier(new RangeNotifier() {
        ....
    });
    try {
        beaconManager.startRangingBeaconsInRegion(regionEstimote);
    } catch (RemoteException e) {
        Log.e(TAG, "RangingActivity", e);
    }
}
Run Code Online (Sandbox Code Playgroud)

BeaconService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if(beaconHistory == null)
        beaconHistory = new …
Run Code Online (Sandbox Code Playgroud)

java android bluetooth ibeacon altbeacon

7
推荐指数
1
解决办法
7784
查看次数

F#for循环错误

我正在玩F#并注意到一个我无法理解的问题.假设我想从用户那里获得一系列整数输入并将其存储在数组中:

[<EntryPoint>]
let main =
    let n = Console.ReadLine() |> int
    let inputVals = Array.zeroCreate n
    for i in 0 .. n - 1 do
        inputVals.[i] <- (Console.ReadLine() |> int)
    printf "%A\n" inputVals 
    0 //compiler error here. The type does not match the expected type
Run Code Online (Sandbox Code Playgroud)

但是这给出了错误

This expression was expected to have type string [] -> int but here has type int
Run Code Online (Sandbox Code Playgroud)

经过一些游戏,我怀疑错误来自for循环.但我无法弄清楚为什么它需要一个字符串[] - > int.这似乎是一个非常简单的问题,但我只能弄清楚发生了什么.

f# for-loop type-mismatch

3
推荐指数
1
解决办法
128
查看次数