我正在尝试将字符串转换为double值,但它并没有让我得到我所期望的...
double dbl;
Double.TryParse("20.0", out dbl);
Run Code Online (Sandbox Code Playgroud)
这段代码返回200.0(而不是20.0)作为double值.知道为什么吗?
我试图在C++中使用一些套接字网络编程.我正在尝试发送文本"Hello World!" 使用C++ send()函数到服务器.首先,我将缓冲区设置为自"Hello World!"以来的13.一共是12个字符(你必须使它比字符数多一个).如果我发送大约7次,send函数只会将字符发送到服务器.当它最终到达服务器时,它看起来像这样:
"Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!Hello World!"
现在这是有趣的部分."Hello World!" 如果我将缓冲区大小设置为256(char buffer [256];),则立即发送句子.说到这样的服务器,它显示"Hello World!" 两个字后有一大堆空格.为什么会发生这种情况,如果可能的话,我该如何解决?请告诉我.
谢谢
我需要一些帮助.我正在创建一个像这样的SelectItem类:
public class SelectItem<T> where T : class
{
public bool IsChecked { get; set; }
public T Item { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我希望以下代码有效
SelectItem<String> obj = new SelectItem<String> { Item = "Value" };
obj.IsChecked = true;
String objValue = obj;
Run Code Online (Sandbox Code Playgroud)
而不是必须这样做:
String objValue = obj.Item;
Run Code Online (Sandbox Code Playgroud)
我怎么能做到这一点?
我正在尝试使用此代码编译POCO
public class MenuItem
{
public string Name
{ get; set; }
public string Url
{ get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我一直在使用以下消息获取编译错误:'MenuItem.Name.get'必须声明一个正文,因为它没有标记为abstract或extern.我错过了什么?我正在本地文件系统网站的App_Code文件夹中编译此类,该文件系统网站设置为编译为.NET 3.5.我知道我以前做过这个,但无法弄清楚我在做什么不同.
修改setter参数是否正常?让我们假设我们有setString方法.我们真的想保留一个修剪过的字符串形式.所以带尾随空格的字符串无效,但我们不想抛出异常.
什么是最好的解决方案?修剪设定器中的值,例如
public void setString(String string) {
this.string = string.trim();
}
Run Code Online (Sandbox Code Playgroud)
或者在调用者中修剪它(不止一次),例如
object.setString(string.trim());
Run Code Online (Sandbox Code Playgroud)
或者别的什么?
虽然我可以将一个字符串向上转换为一个对象,但是我无法将IList字符串向上转换为IList对象.怎么会?现在该怎么做才能将所有项目都复制到一个新的IList?
static void ThisWorks()
{
IList<object> list = new List<object>();
list.Add("I can add a string since string : object");
}
static void ThisDoesNotWork()
{
// throws an invalid cast exception
IList<object> list = (IList<object>) new List<string>();
list.Add("I'm never getting here ... why?");
}
Run Code Online (Sandbox Code Playgroud) 我通常m_在private田野和s_前面的static成员面前添加一个.
用像这样的代码
protected static readonly Random s_Random = new Random ();
Run Code Online (Sandbox Code Playgroud)
我通过VS2008的代码分析得到以下警告:
CA1709:Microsoft.Naming:通过将其更改为"S"来更正成员名称"Bar.s_Random"中's'的大小写.CA1707:Microsoft.Naming:从成员名称"Bar.s_Random"中删除下划线.如何解决这个问题?我应该简单地删除s_?或者为此警告添加全局抑制?
编辑:我的公司缺乏编码标准,所以我可以为我的代码定义它们.(是的我懂...)
如果你认为s_一般应该删除,我很高兴你能提供官方消息来源.
c# code-analysis fxcop naming-conventions visual-studio-2008
在SortedDictionary中是否可以更改项目的值?
我已将用于MVC的 Jeremiah Clark的CheckBoxList Helper翻译成我的VB.Net项目但是当我尝试在我的视图中使用该方法时,我得到了错误
'CheckBoxList' is not a member of 'System.Web.Mvc.HtmlHelper(Of Attenda.Stargate.Web.UserRolesViewModel)'.
Run Code Online (Sandbox Code Playgroud)
谁能告诉我哪里出错了?
助手模块:
Imports System.Runtime.CompilerServices
Public Module InputExtensions
<Extension()> _
Public Function CheckBoxList(ByVal htmlHelper As HtmlHelper, ByVal name As String, ByVal listInfo As List(Of ListItem)) As String
Return htmlHelper.CheckBoxList(name, listInfo, DirectCast(Nothing, IDictionary(Of String, Object)))
End Function
<Extension()> _
Public Function CheckBoxList(ByVal htmlHelper As HtmlHelper, ByVal name As String, ByVal listInfo As List(Of ListItem), ByVal htmlAttributes As Object) As String
Return htmlHelper.CheckBoxList(name, listInfo, DirectCast(New RouteValueDictionary(htmlAttributes), IDictionary(Of String, …Run Code Online (Sandbox Code Playgroud) 如果我有这样的VB声明Public ReadOnly Property Document() As XmlDocument,它的C#等价物是什么?谢谢.
c# ×7
.net ×4
casting ×2
asp.net ×1
asp.net-mvc ×1
buffer ×1
c++ ×1
collections ×1
double ×1
fxcop ×1
generics ×1
html-helper ×1
implicit ×1
properties ×1
setter ×1
sockets ×1
string ×1
vb.net ×1