在c#中从Dictionary中获取随机条目的最佳方法是什么?
我需要从字典中获取一些随机对象以显示在页面上,但是我不能使用以下内容,因为索引无法访问字典:
Random rand = new Random();
Dictionary< string, object> dict = GetDictionary();
return dict[rand.Next()];
Run Code Online (Sandbox Code Playgroud)
有什么建议?
可能重复:
解析/解压缩JavaScript的在线工具
在线javascript minify工具基本上删除了注释和空白.
有没有可以扭转这种情况的工具?通常只需一行代码:
function(){var K=o.timers;for(var J=0;J<K.length;J++){if(!K[J]()){K.splice(J--,1)}}if(!K.length){clearInterval(n);n=g}}
Run Code Online (Sandbox Code Playgroud)
并自动格式化它,以便您可以开始逆向工程?
function(){
var K=o.timers;
for(var J=0;J<K.length;J++){
if(!K[J]()){
K.splice(J--,1);
}
}
if(!K.length){
clearInterval(n);
n=g;
}
}
Run Code Online (Sandbox Code Playgroud) 我试图以MySql格式解析数据,我遇到了SimpleDateFormat.我可以得到正确的日期和月份,但我今年得到了一个奇怪的结果:
date = 2009-06-22;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date d = sdf.parse(date);
System.println(date);
System.println(d.getDate());
System.println(d.getMonth());
System.println(d.getYear());
Run Code Online (Sandbox Code Playgroud)
产出:
2009-06-22
22 OK
5 Hum... Ok, months go from 0 to 11
109 o_O WTF ?
Run Code Online (Sandbox Code Playgroud)
我尝试将格式更改为YYYY-MM-dd(得到错误)和yy-MM-dd(什么也没做).我在Android上编程,不知道它是否重要.
现在,我使用分割绕过它,但它很脏并且阻止我使用i18n功能.
我有一个使用IIS 6的开发机器设置.我在不同的IP地址上配置了3个网站:
默认(全部未分配)WS1(192.168.1.250)WS2(192.168.1.249)
我想知道当我在URL中指定localhost时,IIS如何确定要访问哪个站点?这是可配置的吗?如果是这样,我该怎么做呢?
我一直在针对Cassini(内置的Web开发服务器)开发ASP .NET 3.5 Web应用程序,而不是针对IIS.
在我的Global.asax文件中,在Application_Start事件处理程序中,我有一些代码记录了网站启动的事实.这一切都适用于卡西尼.
由于使用IIS6将站点部署到测试服务器上的虚拟目录,我发现没有写入日志条目,因此我得出结论,Application_Start处理程序未触发.
然后我尝试删除虚拟目录并直接从测试服务器上的网站根目录运行该站点,但它没有任何区别 - 仍然没有应用程序启动的日志条目.
我知道无论我的部署环境如何,这些事件都应该触发,有没有人知道这里出了什么问题?
我有一个可以在桌面应用程序和asp.net网站上使用的assmebly.
在任何一种情况下我都需要处理相对路径(本地文件,而不是URL).
我该如何实现这种方法?
string ResolvePath(string path);
Run Code Online (Sandbox Code Playgroud)
在web环境下,id期望该方法的行为如下(d:\wwwroot\mywebsiteiis指向的文件夹在哪里):
/folder/file.ext => d:\wwwroot\mywebsite\folder\file.ext
~/folder/file.ext => d:\wwwroot\mywebsite\folder\file.ext
d:\wwwroot\mywebsite\folder\file.ext => d:\wwwroot\mywebsite\folder\file.ext
Run Code Online (Sandbox Code Playgroud)
对于桌面环境:( c:\program files\myprogram\bin\.exe的路径在哪里)
/folder/file.ext => c:\program files\myprogram\bin\folder\file.ext
c:\program files\myprogram\bin\folder\file.ext => c:\program files\myprogram\bin\folder\file.ext
Run Code Online (Sandbox Code Playgroud)
我宁愿不IPathResolver根据它的运行状态注入不同的东西.
如何检测我所处的环境,然后在每种情况下我需要做什么来解决可能相对的路径?
谢谢
我有一个Windows Forms应用程序,其中包含已使用Visual Studio创建的安装程序(.msi).我现在正在为2.0版创建一个新的安装程序,其属性RemovePreviousVersions设置为true.
现在,当我在1.0上安装2.0时,它会删除1.0并完全安装2.0.
有没有办法可以告诉安装程序,如果你发现已经安装了一些文件(比如用于数据的.xml文件),那么不要覆盖它们?
我试图让我的2.0安装程序服务于两个目的:
我必须asp:TextBox保持金钱价值,即'1000','1000,0'和'1000,00'(逗号是俄罗斯标准的分隔符).
我ValidationExpression有什么用asp:RegularExpressionValidator呢?
我试过\d+\,\d{0,2}但它不允许没有十进制数字的数字,例如只是'1000'.
我有一些代码:
public static void ReadTextFile()
{
string line;
// Read the file and display it line by line.
using (StreamReader file = new StreamReader(@"C:\Documents and Settings\Administrator\Desktop\snpprivatesellerlist.txt"))
{
while ((line = file.ReadLine()) != null)
{
char[] delimiters = new char[] { '\t' };
string[] parts = line.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < parts.Length; i++)
{
Console.WriteLine(parts[i]);
sepList.Add(parts[i]);
}
}
file.Close();
}
// Suspend the screen.
Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)
它读入包含由制表符分隔的数据的文本文件,并将数据拆分为单独的单词.
我遇到的问题是,一旦数据被分离,它在列表中的随机字符串的左侧和右侧仍然有大量的空白区域(事实上大多数都是这样).我无法修剪字符串,因为它只删除了空格,从技术上讲,这不是空格.
任何人都有任何关于如何解决这个问题的想法!?
c# ×5
.net ×2
asp.net ×2
android ×1
currency ×1
date-parsing ×1
dictionary ×1
iis ×1
iis-6 ×1
installation ×1
java ×1
javascript ×1
minify ×1
path ×1
regex ×1
tabs ×1
text-files ×1
unminify ×1
vdproj ×1