I want to write method which generates key for cache object.
This is my function:
public static string GenerateKeyForCache(string jobName, params object[] keys )
{
var generatedKey = keys.Aggregate(string.Empty, (current, key) => current + (key + "-"));
return jobName + "-" + new string(generatedKey.Take(generatedKey.Length - 1).ToArray());
}
This code generated key for cache, for example we have the following call:
CacheUtils.GenerateKeyForCache("JobName", "1","2","3");
The method is generated the following key: "JobName-1-2-3".
What is best approach to do this?
Why not just use String methods?
No need for
AggreagteorTake…keep it simple