我想每隔5分钟调用一些方法.我怎样才能做到这一点?
public class Program
{
static void Main(string[] args)
{
Console.WriteLine("*** calling MyMethod *** ");
Console.ReadLine();
}
private MyMethod()
{
Console.WriteLine("*** Method is executed at {0} ***", DateTime.Now);
Console.ReadLine();
}
}
Run Code Online (Sandbox Code Playgroud) 我想从字符串中删除最后三个字符:
string myString = "abcdxxx";
Run Code Online (Sandbox Code Playgroud)
请注意,该字符串是动态数据.
我正在读取文件内容,并在这样的确切位置获取字符串
string fileContentMessage = File.ReadAllText(filename).Substring(411, 3);
Run Code Online (Sandbox Code Playgroud)
输出将始终为Ok
或Err
在另一边我MyObject
这有ContentEnum
这样的
public class MyObject
{
public enum ContentEnum { Ok = 1, Err = 2 };
public ContentEnum Content { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
现在,在客户端我想使用这样的代码(将我的字符串转换fileContentMessage
为Content
属性)
string fileContentMessage = File.ReadAllText(filename).Substring(411, 3);
MyObject myObj = new MyObject ()
{
Content = /// ///,
};
Run Code Online (Sandbox Code Playgroud) 是否可以使用数据注释为int属性添加默认值
就像是
[DefaultValue=1]
public int MyId {get; set;}
Run Code Online (Sandbox Code Playgroud) 我在剃刀视图(javascript代码)中有对象数组.
var myArr;
Run Code Online (Sandbox Code Playgroud)
在页面加载包含让我们说10个对象.
一个对象具有以下结构
- Id
- Name
Run Code Online (Sandbox Code Playgroud)
我怎么能从js数组中删除对象,知道它是Id?
我想表示以下字符串:
aaaa,23,"something inside double quotes", 99, 8, 7
Run Code Online (Sandbox Code Playgroud)
我正在考虑使用以下方法String.Format
:
StringBuilder.AppendLine(string.Format("{0},{1},{2},{3},{4},{5}",
item.one, item.two, item.three, item.four, item.five, item.six));
Run Code Online (Sandbox Code Playgroud)
我需要{2}
用双引号包装第三个参数.
我将日期表示为整数20140820
,我希望将其解析为日期时间,如2014.08.20.
我是否需要使用索引解析每个整数值(2014)(08)(02)还是更简单的方法?
我得到string
了参数.
每个字符串应该占用30个字符.现在我检查它的长度后,我想在末尾添加空格,如果传递的字符串长度为25个字符,我想再添加5个空格.
问题是,如何在字符串中添加空格?
我有一个方法,它需要两个日期时间参数
public void SomeReport(DateTime TimeFrom, DateTime TimeTo)
{
// ommited
TimeFrom.ToString("ddMMyy"), TimeTo.ToString("ddMMyy")));
// ommited
}
Run Code Online (Sandbox Code Playgroud)
当我发送这个参数时
DateTime TimeTo = DateTime.Now;
DateTime TimeFrom = new DateTime().AddHours(-1);
Run Code Online (Sandbox Code Playgroud)
发生此错误:
System.ArgumentOutOfRangeException:添加或减去的值导致无法表示的DateTime.
可能是什么问题?
在剃刀视图中,我使用模型来渲染标签
@Html.LabelFor(model => model.MyName, htmlAttributes: new { @class = "control-label col-md-6" })
Run Code Online (Sandbox Code Playgroud)
现在我想使用它的值而不是数据注释attr.值,所以我尝试使用DisplayFor之类的
@Html.DisplayFor(model => model.MyName, new { @class = "control-label col-md-6" })
Run Code Online (Sandbox Code Playgroud)
这个css类control-label col-md-6
不适用.为什么?
c# ×9
.net ×4
string ×3
asp.net-mvc ×2
datetime ×2
casting ×1
enums ×1
javascript ×1
jquery ×1
razor ×1