我正在编写一个带有开箱即用的表单和数据集的快速实用程序应用程序。
require 'httparty'
class LolObserver
include HTTParty
default_timeout(1) #timeout after 1 second
attr_reader :api_key, :playerid, :domain
attr_accessor :region
def initialize(region,playerid,apikey)
@region = region_server(region)
@playerid = playerid
@api_key = apikey
end
def region_server(region)
case region
when "euw"
@domain = "https://euw.api.pvp.net"
self.region = "EUW1"
when "na"
@domain = "https://na.api.pvp.net"
self.region = "NA1"
end
end
def handle_timeouts
begin
yield
#Timeout::Error, is raised if a chunk of the response cannot be read within the read_timeout.
#Timeout::Error, is raised if a connection cannot be created within the open_timeout.
rescue Net::OpenTimeout, Net::ReadTimeout
#todo
end
end
def base_path
"/observer-mode/rest/consumer/getSpectatorGameInfo"
end
def current_game_info
handle_timeouts do
url = "#{domain}/#{ base_path }/#{region}/#{playerid}?api_key=#{api_key}"
puts '------------------------------'
puts url
HTTParty.get(url,:debug_output => $stdout)
end
end
end
查看该行是否已存在的查询是否具有哈希查找的性能,或者它最终会反复搜索整个集合?
答案 0 :(得分:0)
您可以构建一个为任何列提供哈希的字典
DataTable dt = new DataTable();
Dictionary<string, List<DataRow>> dict = dt.AsEnumerable()
.GroupBy(x => x.Field<string>("Col A"), y => y)
.ToDictionary(x => x.Key, y => y.ToList());
如果每个键只有一个值,请使用此
Dictionary<string, DataRow> dict = dt.AsEnumerable()
.GroupBy(x => x.Field<string>("Col A"), y => y)
.ToDictionary(x => x.Key, y => y.FirstOrDefault());