请帮助我们解决"几乎"的争议一切都是一个对象(Stack Overflow问题的答案作为一个新手,在学习C#之前有什么我应该注意的吗?).我认为就是这种情况,因为Visual Studio中的所有内容至少都显示为结构体.请张贴参考文献,以免它变成"现代傻瓜"(This American Life).
请注意,这个问题涉及C#,不一定是.NET,以及它如何处理引擎盖下的数据(显然它都是1和0).
以下是"一切都是对象"的评论:
对象的定义:"对象"作为类System.Object的继承者与"对象"作为类型与"对象"作为引用类型的实例."
在网页上,我使用CSS将我的所有图像缩放50%,使它们在视网膜屏幕上看起来很清晰但是对于平铺图像不起作用,似乎没有办法缩放平铺背景图像,以便在视网膜屏幕上它将是锐利的而不是双倍大小.对不起,如果这个问题令人困惑.
我广泛使用了继承,多态,封装,但我才意识到我不知道对象范围与变量的以下行为.差异最好用代码显示:
public class Obj
{
public string sss {get; set;}
public Obj()
{
sss = "0";
}
}
public partial class testScope : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Obj a = new Obj();
String sss = "0";
Context.Response.Write(sss); // 0
FlipString(sss);
FlipString(a.sss);
Context.Response.Write(sss + a.sss); // 0 0
FlipObject(a);
Context.Response.Write(a.sss); // 1
Context.Response.End();
}
public void FlipString(string str)
{ str = "1"; }
public void FlipObject(Obj str)
{ str.sss = "1"; }
}
Run Code Online (Sandbox Code Playgroud)
所以我认为当变量传递给方法时,更改仅限于方法的范围.但似乎如果一个对象被传递给一个更改为它的方法,那么它的属性将超出该方法.
我可以接受这个,如果规则是这个行为存在于对象而不是变量,但在.net中,一切都是一个对象,一个字符串(就像示例中的那个是System.String)那么规则怎么样,我怎么能预测我传入方法的参数范围?
所以我有这个网址:http: //test.com/afolder/who-else-wants-to-make-horror-movies%3f/
这是URL编码版本:http: //test.com/afolder/who-else-wants-to-make-horror-movies?/
但IIS7抛出400:
HTTP错误400.0 - 错误请求ASP.NET在URL中检测到无效字符.
但是,如果我正确编码了URL,为什么会这样做呢?
我也遇到了与其他URL编码字符相同的问题,例如'/',即'%2f',但当.net解析处理程序时,它解码了URL,然后更改了有效路径grrrr.
我想获得一个可以从SP中获得的结果集和列的列表.我已经能够得到参数,脚本......但我不知道从哪里得到结果集和列名.
using Microsoft.SqlServer.Management.Smo;
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["mydbconn"].ConnectionString))
{
conn.Open();
Server sv = new Server(new Microsoft.SqlServer.Management.Common.ServerConnection(conn));
Database db = sv.Databases["mydb"];
foreach (StoredProcedure sp in db.StoredProcedures)
{
string[] columns = sp.??????
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法进入列?我最终试图编写一个代码生成器来自动编写数据访问对象.谢谢!
编辑:"另一个解决方案是,如果你可以获得ScalarResult的值,你可以将它转换为有用的东西,你可以从中派生出来." :任何想法如何实现?
我有100个类,有一些类似的元素和一些独特的.我创建了一个界面来命名那些相似的项目,例如:interface IAnimal.我通常做的是:
class dog : IAnimal
Run Code Online (Sandbox Code Playgroud)
但是有100个课程,我不觉得他们全部都在寻找那些我可以应用IAnimal的课程.
我想要做的是:
dog scruffy = new dog();
cat ruffles = new cat();
IAnimal[] animals = new IAnimal[] {scruffy as IAnimal, ruffles as IAnimal} // gives null
Run Code Online (Sandbox Code Playgroud)
要么
IAnimal[] animals = new IAnimal[] {(IAnimal)scruffy, (IAnimal)ruffles} //throws exception
Run Code Online (Sandbox Code Playgroud)
然后做
foreach (IAnimal animal in animals)
{
animal.eat();
}
Run Code Online (Sandbox Code Playgroud)
有没有办法让c#让我把ruffles和scruffy视为一个IAnimal而不必写:IAnimal在写这个类时.
谢谢!
编辑(不是懒惰):类是从sql存储的proc元数据生成的,这意味着每次生成它时我都必须返回并添加它们,或者修改代码生成器以识别接口中的成员,实际上这不是一个坏主意.我希望有某种泛型方法或者某种东西.
我想只选择表中第一级'td'元素而不是任何嵌套表的单元格.例如:
<table id="Outer">
<tr>
<td> --this one
</td>
<td> --this one
<table>
<tr>
<td></td> -- but not this one or any deeper nested cells
</tr>
</table>
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
(在prod代码中是的,我会包括tbody,thead ...)
我想将我的框架移植到新的.net核心,所以我创建了一个空的应用程序,添加了一个静态成员来感受行为,为每个请求增加一个int,但它运行两次,一次用于请求和一旦在请求之后,所以不是得到1,2,3,4 ......我得到1,3,5,7 ......
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
app.UseIISPlatformHandler();
app.Run(async (context) =>
{
state++;
await context.Response.WriteAsync(state.ToString());
});
}
public static int state;
// Entry …Run Code Online (Sandbox Code Playgroud)