• About Us
  • Blog
  • Basket
  • Account
  • Sign In


Published on Tuesday, October 13, 2015

Calculate Maximum Size of a Value String

Use C# to determine the longest value returned from device detection

The following C# code creates a data set instance from a source pattern binary uncompressed data file. A foreach loop uses Linq to iterate through each of the Components contained in the data set (currently Hardware, Operating System, Browser and Crawler) and their associated Profiles. All the values returned from the available properties for the profile are fetched and their lengths checked against the maximum length found so far. The longest values is finally output after all profiles have been checked.

int profiles = 0;
int maxLength = 0;
using (var dataSet = MemoryFactory.Create(
  foreach(var profile in dataSet.Components.SelectMany(i => i.Profiles))
    foreach(var property in profile.Component.Properties)
      var value = profile[property];
      if (value != null &&
          value.ToString().Length > maxLength)
        maxLength = value.ToString().Length;
    if (profiles % 1000 == 0) 
      Console.WriteLine("Processed '{0}' Profiles", profiles);  
Console.WriteLine("Maximum value string length '{0}'", maxLength);

This code shows how easy it is to access meta data using the 51Degrees APIs. The code could be adapted to provide values for user interfaces, provide meta data for reports, or extract device values from profile IDs stored during real time detection.

All versions of the 51Degrees data including Lite, Premium and Enterprise are supported.

Compare Data Options

Comments (0)

Author: Products Team

Categories: Development

Tags: C# , Meta Data

James Rosewell Host

Products Team

Other posts by Products Team
Contact author



.NET 2013 2014 4G 51Degrees 5G A.C.Roma A7 ABI Acer Adtech Affiliate Marketing Afilias Alcatel Amazon AMP Analysis Analytics Android Android 5.0 Lollipop Android Kitkat Android Lollipop Android Media Stick Apache API Apple Apple TV Archos Asha Asian Market ASP.NET Asus Australia Big Data Black Friday Blackberry Blink Browser C C# Case Study CeBIT CES Chrome Cloud CMS combinations Comparison Competition CoolPad COTW Cron CSS3 Data Data Blog Data File Data Model Daydream Denver Design Desire Eye Desktop Detection Developers Device Device Data Device Detection Device Intelligence Device Popularity Device property Device Types Device Use DeviceAtlas Display dmexco DoCoMo Doogee DotNetNuke Download Drupal Email EReader E-Reader Ericsson Evaluation Event Examples EXPLAY Rio Facebook feature Firefox Firefox OS Fly Foundation Framework France Galaxy S3 Galaxy S5 Galaxy Tab A Galaxy Tab A 8.0 Galaxy Tab A 9.7 Germany git repositories Global Google Google Daydream GSMA HAProxy Hardware Hisense HTC HTC ONE MAX HTC OS HTML5 HTTP HTTP Headers Huawei HUAWEI. UPDATE HUDL Huwaei IBC Icemobile Prime 4.0 IE IFA IIS Image Optimiser Image Optimizer India Infographic Ingeniux Internet usage iOS iOS 7 iOS 8 ipad iPhone iPhone 6 IsEmailBrowser IsWebApp Italy Japan Java Javascript Jolla Kentico Keynote Kindle Kindle Fire Kindle Fire HD Leagoo Lenovo LG Location Log File Analysis LTE Lumia m.dot macOS Map Memory Meta Data Mi 4S Micromax Microsoft Miia Style Mobile Mobile Analysis Mobile Analytics Mobile Devices Mobile Marketing Mixer Module Motorola MVC4 MWC MWC 2017 MWC16 MyPhone Native Native Apps NET New Release News News Letter Nexus Nexus 6 Nexus 9 NFC NGINX Nokia Nokia 3310 Non-Mobile NVIDIA Omate On7 OnePlus 5 Opera Opera Mini Operating System Optimisation OS OSX 10.10 OTA Panasonic Patent PC Pebble Performance phablet phone PHP Poland Presentation Press Release Price Band PRIV programmatic PS4 Publishers Python QMobile QR Codes Redirection Research Reseller Responsive Images Responsive web design RESS Review reviews RIM Ringmark RTB RWD Safari Samsung Scala ScientiaMobile Screen Screen resolution Screen Size SEO Server Server-side optimisation Set Box Set Top Box Sharepoint Shark 1 SHIFT phones Sitecore Sitecore version 9 SLUSH Smart TV Smartphone Smartphones Smartwatches Snapdragon Sony Sony Xperia Spain Swedish Beers Symbian Tablet Tablets Tesco Testing Tips Top 5 TOTW TV UDS UK Umbraco Update updates US User Agent UserAgent User-Agent Vendors Version 3 Video VoLTE VR Wearable Web Web Apps Web content management WebKit WebMatrix White Paper Widgets Widnows WiFi Wiko Wileyfox Windows Windows Phone WURFL Xbox XBox One Xiaomi Xperia Xperia z Yosemite Z10 ZenFon 2 ZOPO ZTE