只是想知道最新版本MVC的.net framework.
谷歌搜索,没有发现有关的信息MVC history and the latest version.
这个网站http://www.asp.net/mvc有教程MVC 5.这是否意味着MVC 5是最新的?
我也发现在谷歌,一些网站提到NuGet Gallery | Lib.Web.Mvc 6.0.1.那么,6.1是最新的吗?
或者我错过了一些我们总能参考的信息/网站,了解每个框架中的最新信息以及更多信息?
对不起,如果这个问题太天真了.提前致谢.
要检查字符串是否为空,我使用
var test = string.Empty;
if (test.Length == 0) Console.WriteLine("String is empty!");
if (!(test.Any())) Console.WriteLine("String is empty!");
if (test.Count() == 0) Console.WriteLine("String is empty!");
if (String.IsNullOrWhiteSpace(test)) Console.WriteLine("String is empty!");
Run Code Online (Sandbox Code Playgroud)
以上所有语句都产生相同的输出.我应该使用的最佳方法是什么?
var s = Convert.ToString(test);
s = test.ToString(CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)同样,两个陈述都做同样的事情.什么是最好的使用方法?
我试过调试以及如何对C#语句的性能进行基准测试?
在如下的非常简单的类中,
class Program
{
public Program(int a, int b, int c)
{
Console.WriteLine(a);
Console.WriteLine(b);
Console.WriteLine(c);
}
}
Run Code Online (Sandbox Code Playgroud)
我使用反射来调用构造函数
像这样的东西......
var constructorInfo = typeof(Program).GetConstructor(new[] { typeof(int), typeof(int), typeof(int) });
object[] lobject = new object[] { };
int one = 1;
int two = 2;
int three = 3;
lobject[0] = one;
lobject[1] = two;
lobject[2] = three;
if (constructorInfo != null)
{
constructorInfo.Invoke(constructorInfo, lobject.ToArray);
}
Run Code Online (Sandbox Code Playgroud)
但我收到一个错误,说"对象与目标类型构造函数不匹配".
任何帮助/评论非常感谢.提前致谢.
我的字符串是:
<div> (blah blah blah) ---> quite big HTML before coming to this line.<b>Train No. & Name : </b></td><td style="border-bottom:1px solid #ccc;font:12px arial"><span>12672 / SOUTH TRUNK EXP</span></td>
Run Code Online (Sandbox Code Playgroud)
我设法制定了一个正则表达式
var trainDetails = new RegExp("<b>Train No. & Name : </b></td><td.*>([0-9][a-z][A-Z]+)</span></td>", "m");
Run Code Online (Sandbox Code Playgroud)
但是trainDetails为null或为空.
我所要做的就是在span元素中获取列车名称和列车编号.
我做错了什么指针?
我在某处读到了
"抽象和密封修饰符相当于一个静态的类"
我也发现了
"当你声明一个静态类时,编译器在内部标记类抽象并密封,并在IL代码中创建一个私有构造函数"
所以,我决定这样做:
static class A
{
public static void test()
{
Console.WriteLine("test");
}
}
Run Code Online (Sandbox Code Playgroud)
现在,类"A"不能被继承或实例化.
所以,让我们写class B使用abstract,以防止实例化和使用sealed,防止继承.
但是,这种方法失败了.
这相当于
public abstract sealed class B
{
private B()
{
}
public void test()
{
Console.WriteLine("test");
}
}
Run Code Online (Sandbox Code Playgroud)
But I recieve an error stating "error CS0418:B':抽象类不能被密封或静态"`.任何想法为什么这是不可能的?
提前感谢您的回答.
已经清楚的是since the structs are value types in c#, they are stored on stack,a class object is stored on the heap(它的参考,当然存储在堆栈上).
警告:( 是的,这可能并非总是如此.感谢@Jon进行更正)但在大多数情况下,是的!
但是,怎么样a class one of whose member is of type struct?现在,内存模型将如何?
顺便说一句,我怎么检查是否存在对象驻留在stack或heap?
好的.一些假设:
member不是一个variable.(感谢更正.)我在阅读有关Attribute Routing in Web API 2从这里
文章说,
Here are some other patterns that attribute routing makes easy.
API versioning
In this example, “/api/v1/products” would be routed to a different controller than “/api/v2/products”.
/api/v1/products
/api/v2/products
Run Code Online (Sandbox Code Playgroud)
怎么会?
编辑:我会在正常路由中执行此操作:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/v2/products",
defaults: new { controller = V2_Products }
);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/v1/products",
defaults: new { controller = V1_Products }
);
} …Run Code Online (Sandbox Code Playgroud) 问题:编写一个可以同时接受List<int>和的方法声明int[]
我的答案涉及这样的事情:
void TestMethod(object param) // as object is the base class which can accept both int[] and List<int>
但这不是预期的答案,她这么说.
任何想法如何签署方法?
刚刚开始编写单元测试,现在我已经被这种情况阻止了:
我有一个方法,它有一个FileStream对象,我试图传递一个"字符串".所以,我想将我的字符串转换为FileStream,我这样做:
File.WriteAllText(string.Concat(Environment.ExpandEnvironmentVariables("%temp%"),
@"/test.txt"), testFileContent); //writes my string to a temp file!
new FileStream(string.Concat(Environment.ExpandEnvironmentVariables("%temp%"),
@"/test.txt"), FileMode.Open) //open that temp file and uses it as a fileStream!
Run Code Online (Sandbox Code Playgroud)
然后关闭文件!
但是,我想必须有一些非常简单的替代方法将字符串转换为fileStream.
欢迎提出建议![注意在stackoverflow中有这个问题的其他答案,但似乎没有一个直接的解决方案]
提前致谢!
这是UserControl我正在使用的.
this.CardHolderName.Content是label在用户控件的UI中.
public partial class PersonCredential : UserControl
{
public PersonCredential()
{
InitializeComponent();
Dispatcher.BeginInvoke( (Action) (() => {
SCLib type = new SCLib();
type.StartMonitoring();
type.CardArrived += (string ATR) => { this.CardHolderName.Content = ATR; };
};
}));
Run Code Online (Sandbox Code Playgroud)
我仍然得到错误," 调用线程无法访问此对象,因为不同的线程拥有它 "即使我正在使用它Dispatcher.BeginInvoke.
Dispatcher使用方式有什么问题吗?}
编辑:我在内容控件中实例化用户控件,代码隐藏是:
public partial class MainWindow : Window
{
PersonCredential personCredential {get;set;}
public MainWindow()
{
InitializeComponent();
var personCredential = new CoffeeShop.PersonCredential();
//create an instance of user control.
this.personCredentials.Content = personCredential;
// assign it to …Run Code Online (Sandbox Code Playgroud) c# ×9
.net ×6
.net-4.0 ×4
asp.net ×2
asp.net-mvc ×1
c#-4.0 ×1
dispatcher ×1
filestream ×1
html ×1
javascript ×1
oop ×1
reflection ×1
regex ×1
routing ×1
static ×1
wpf ×1