小编Sun*_*nil的帖子

int.TryParse()为"#.##"返回false

我有一个接收字符串参数并将它们转换为整数的函数.
为了安全转换,使用int.TryParse().

public IEnumerable<object> ReportView(string param1, string param2)
{
  int storeId = int.TryParse(param1, out storeId) ? storeId : 0;
  int titleId = int.TryParse(param2, out titleId) ? titleId : 0;
  IEnumerable<object> detailView = new Report().GetData(storeId, titleId);
  return detailView;
}
Run Code Online (Sandbox Code Playgroud)

函数调用ReportView("2","4") - > int.Tryparse成功解析数字
函数调用ReportView("2.00","4.00") - > int.TryParse无法解析数字

为什么?任何的想法?

@Update
对不起,伙计们,我的观念错了.我是c#的新手,我以为Int.TryParse()将返回整数部分并忽略小数.但它不会,甚至Convert.ToInt32("字符串")
感谢所有.

c# tryparse

15
推荐指数
4
解决办法
1万
查看次数

查看System.Web.HttpRuntime.Cache中缓存的数据

是否有任何工具可用于查看HttpRunTime缓存中的缓存数据..?
我们有一个Asp.Net应用程序,它将数据缓存到HttpRuntime Cache中.给定的默认值为60秒,但后来更改为5分钟.但感觉缓存的数据在5分钟之前就会刷新.不知道底下发生了什么.

有没有可用的工具或我们如何看到HttpRunTime Cache中缓存的数据....有效期...?
以下代码用于添加要缓存的项目.

    public static void Add(string pName, object pValue)
    {
    int cacheExpiry= int.TryParse(System.Configuration.ConfigurationManager.AppSettings["CacheExpirationInSec"], out cacheExpiry)?cacheExpiry:60;
    System.Web.HttpRuntime.Cache.Add(pName, pValue, null, DateTime.Now.AddSeconds(cacheExpiry), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
    }
Run Code Online (Sandbox Code Playgroud)


谢谢.

c# asp.net httpruntime.cache

12
推荐指数
2
解决办法
1万
查看次数

XML解析:第1行,第23个字符,非法名称字符

有谁知道为什么这个XML文本在SQL Server 2008中抛出非法的名字符错误?

'<cs><c a="2" b="CITY & STATE TX" c="CITY & STATE TX"/></cs>'
Run Code Online (Sandbox Code Playgroud)

异常消息是

Msg 9421, Level 16, State 1, Line 2
XML parsing: line 1, character 23, illegal name character
Run Code Online (Sandbox Code Playgroud)

以下是用于解析此xml的查询

DECLARE @CaptionsDescriptions XML = '<cs><c a="2" b="CITY & STATE TX" c="CITY & STATE TX"/></cs>'

DECLARE @DocHandle int  
DECLARE @CaptionsDescriptionsTable TABLE  
(  
 ID INT IDENTITY(1,1),  
 languageID INT,  
 Caption  VARCHAR(50),  
 Description VARCHAR(2000)  
)  

EXEC sp_xml_preparedocument @DocHandle OUTPUT,@CaptionsDescriptions    
INSERT INTO @CaptionsDescriptionsTable SELECT a,b,c  
 FROM OPENXML(@DocHandle,'cs/c')   
 WITH (  
    a int, -- language …
Run Code Online (Sandbox Code Playgroud)

xml sql-server-2008

9
推荐指数
2
解决办法
4万
查看次数

在C#和VB.Net中启动数组索引

看看下面的代码.,

C#

 string[] testString = new string[jobs.Count];
Run Code Online (Sandbox Code Playgroud)

相当于VB.Net

Dim testString() As String = New String(jobs.Count - 1) {}
Run Code Online (Sandbox Code Playgroud)

为什么在创建新数组时在vb.net中使用'jobs.Count - 1'代替'jobs.Count'?

c# vb.net arrays

7
推荐指数
2
解决办法
7387
查看次数

HttpRuntime Cache ....中的项目的有效期限是多少?

我们可以在HttpRuntime Cache中为一个项目设置的最大到期时间是多少?
另外,默认的到期时间是多少?

public static void Add(string pName, object pValue)
{
  System.Web.HttpRuntime.Cache.Add(pName, pValue, null, DateTime.Now.AddSeconds(60), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
}
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,第4个参数是'absoluteExpiration'。
我们在这里可以提供的最大价值是多少...?

如果我提供2014年5月5日,该项目可以在高速缓存中使用很长时间吗?
(此查询与AppFabric缓存的实现有关。尝试用AppFabric缓存替换Httpruntime缓存)。

c# asp.net httpruntime.cache

5
推荐指数
1
解决办法
9003
查看次数

客户端配置文件出错

我正在尝试创建一个AppFabric缓存客户端,它是一个控制台应用程序.但在创建DataCacheFactory的新实例时,在客户端配置文件中收到错误Error.
连接设置在App.Config文件中提供,如msdn中所述.

static void Main(string[] args)
{
  try
  {
    DataCacheFactory dFact = new DataCacheFactory();
    DataCache myCache = dFact.GetCache("default");

    myCache.Remove("pValue");
    myCache.Add("pValue", "Test Cache Value");
    Console.WriteLine(string.Format("{0}", "Added to cache. Press any key to read...."));
    Console.ReadLine();
    Console.WriteLine(string.Format("{0}", myCache.Get("pValue").ToString()));
    Console.ReadLine();
  }
  catch (Exception Ex)
  {
    throw new System.Exception(Ex.ToString());
  }

}
Run Code Online (Sandbox Code Playgroud)

}
App.config文件

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>

<configSections>
<section name="dataCacheClient"
 type="Microsoft.ApplicationServer.Caching.DataCacheClientSection,
 Microsoft.ApplicationServer.Caching.Core,Version=1.0.0.0,Culture=neutral,
 PublicKeyToken=31bf3856ad364e35"
         allowLocation="true"
         allowDefinition="Everywhere" />
 </configSections>
 <dataCacheClient>
 <hosts>
  <host  name="localhost" …
Run Code Online (Sandbox Code Playgroud)

.net c# caching appfabric

3
推荐指数
1
解决办法
3874
查看次数