• 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 4G 51Degrees 5G Acer Adform Adtech Advertising Afilias Alcatel Amazon AMP Analysis Analytics Android Apache API Apple Asian Market ASP.NET Asus Blackberry Browser C C# Centro Chrome chromium Client hints Cloud CMS CPU CSS3 Data Data Blog Data File Daydream Design Detection Developers Device Device Data Device Detection Device Intelligence Device Models Device property DeviceAtlas Disney dmexco DotNetNuke Download ebay Ericsson Event Facebook Firefox Foundation Framework Galaxy git repositories Google Google Analytics Google Daydream GPU GSMA Guess HAProxy Hash Trie HTC HTML5 HTTP HTTP Headers Huawei Infinix Ingeniux Internet usage iOS iOS 13 ipad iPadOS iPhone iPhone 11 Java Javascript Kentico LG Liferay LTE m.dot Memory Memory leak Meta Data Microsoft Mobile Mobile Analysis Mobile Analytics Mobile Devices Mobile Marketing Mixer Motorola Mozilla MWC MWC 2017 MWC16 Native Apps NET New Release News Nexus NFC NGINX Nokia OnePlus 5 Opera Operating System Oppo Optimisation OS Patent Performance PHP Press Release Price Band programmatic Publishers Python Redirection Research Responsive Images Responsive web design RESS Review RTB RWD Safari Samsung Scala ScientiaMobile SEO Server Server-side optimisation Seznam.cz Sitecore Smart TV Smartphone Smartwatches Sony Swedish Beers Tablet Tencent Testing Tips Tutorial Umbraco Update User Agent User-Agent Valgrind Varnish Varnish Cache Video Vodafone VoLTE Web Web Apps Web content management Webtrekk White Paper Widgets WiFi Windows WURFL Xiaomi Xperia ZTE