草庐IT

using-size-classes-xcode

全部标签

c# - OOPS 概念 : What is the difference in passing object reference to interface and creating class object in C#?

我有一个类CustomerNew和一个接口(interface)ICustomer:publicclassCustomerNew:ICustomer{publicvoidA(){MessageBox.Show("Classmethod");}voidICustomer.A(){MessageBox.Show("Interfacemethod");}publicvoidB(){MessageBox.Show("ClassMethod");}}publicinterfaceICustomer{voidA();}我对这两行代码很困惑。ICustomerobjnew=newCustomerNe

c++-cli - C++/CLI-问题: Is there an equivalent to the C# "is" keyword or do I have to use reflection?

我在MSDN的某个地方读到过,与C#的“is”关键字等效的是dynamic_cast,但这并不完全等效:它不适用于值类型或泛型参数。例如在C#中我可以写:voidMyGenericFunction(){objectx=...if(xisT)...;}如果我尝试“等效的”C++/CLI:genericvoidMyGenericFunction(){objectx=...if(dynamic_cast(x))...;}我收到编译器错误“errorC2682:cannotuse'dynamic_cast'toconvertfrom'System::Object^'to'T'”。我唯一能想到的

c# - "Collection was of a fixed size"带有 POCO 的 EF4 异常

我将EF4与WCF和POCO结合使用。我删除了POCO实体中的所有虚拟关键字。我有Employee和Team实体,两者之间的关系是1:N,意味着一名员工只能分配到一个团队。我想在现有团队中添加新员工。以下代码在客户端。privatevoidbtnAdd_Click(objectsender,RoutedEventArgse){TeamteamFromDb=ServiceProxy.GetService.GetTeamById(181);EmployeenewEmp=newEmployee{UserName="username"};newEmp.Team=teamFromDb;Servi

c# - 隐式类型数组 : why we can't set array size explicitly?

C#语言规范(7.6.10.4)说,数组创建表达式有树种:newnon-array-type[expression-list]rank-specifiersoptarray-initializeroptnewarray-typearray-initializernewrank-specifierarray-initializer第三个用于隐式类型数组:varfoo=new[]{1,2,3};问题:在隐式类型数组的情况下,是否有任何重要的理由禁止显式设置数组大小?与这种语法相比,它看起来像是不对称行为:varfoo=newint[3]{1,2,3};更新。稍微澄清一下。我可以看到,显式设

c# - "using"构造和异常处理

“using”结构对于需要开始和分开的结束部分的情况看起来非常方便。快速举例说明:using(newTag("body")){Trace.WriteLine("hello!");}//...classTag:IDisposable{Stringname;publicTag(Stringname){this.name=name;Trace.WriteLine("");Trace.Indent();}publicvoidDispose(){Trace.Unindent();Trace.WriteLine("")}}开始部分定义为构造函数,结束部分为Dispose方法。然而,尽管这个结构很有

c# - .NET 反编译器区分 "using"和 "try...finally"

给定以下C#代码,其中Dispose方法以两种不同的方式调用:classDisposable:IDisposable{publicvoidDispose(){}}classProgram{staticvoidMain(string[]args){using(vardisposable1=newDisposable()){Console.WriteLine("using");}vardisposable2=newDisposable();try{Console.WriteLine("try");}finally{if(disposable2!=null)((IDisposable)dis

c# - 我怎样才能让 VS2010 insert using statements 按照 StyleCop 规则规定的顺序

相关的默认StyleCop规则是:将using语句放在namespace中。按字母顺序对using语句进行排序。但是...Systemusing排在第一位(仍在尝试弄清楚这是否意味着只是usingSystem;或using系统[.*];).所以,我的用例:我发现了一个错误并决定我至少需要添加一个可理解的断言,以减轻下一个人调试的痛苦。所以我开始输入Debug.Assert(并且intellisense将其标记为红色。我将鼠标悬停在Debug上以及usingSystem.Diagnostics;和System.Diagnostics.Debug我选择前者。这会在所有其他using语句之后

c# - Entity Framework : Alternate solution to using non primary unique keys in an association

我知道EntityFramework不允许您使用非主唯一键作为外键关联从数据库生成模型。我可以手动修改EDMX吗?如果是这样,有人可以给我一个例子或引用吗?如果不是,还有其他可能吗?最简单的例子:这是表的DDL。您会注意到我有一个从PersonType.TypeCode到Person.TypeCode的外键CREATETABLE[dbo].[PersonType]([PersonTypeId][int]NOTNULL,[TypeCode][varchar](10)NOTNULL,[TypeDesc][varchar](max)NULL,CONSTRAINT[PK_PersonType]

c# - (关于最佳实践的问题)为什么默认有 "using System.Text"?

每次我创建一个类时,我都会看到默认添加的usingSystem.Text(以及其他using)。每次我都会在一段时间后删除它,因为根据ReSharper,它未被使用。我是否缺少最佳实践?你经常使用那个命名空间吗?在什么情况下?必须有一个默认引用此命名空间的原因。谢谢! 最佳答案 System.Text命名空间包含类、抽象基类和辅助类。例如,如果您想利用StringBuilder、Decoder、Encoder等...。上述类在.net中的大多数情况下起着重要作用。但它没有必要出现在您的代码中。它只适用于你需要它的时候。重要的是要知道

c# - Firebase 3 : creating a custom authentication token using . 网络和 c#

我正在尝试使用自定义token实现Firebase3身份验证机制(如https://firebase.google.com/docs/auth/server/create-custom-tokens中所述)。我的服务器是ASP.NETMVC应用程序。因此,根据说明(https://firebase.google.com/docs/server/setup),我为我的Firebase应用程序创建了一个服务帐户,并生成了一个“.p12”格式的key。之后,根据此处的说明(https://firebase.google.com/docs/auth/server/create-custom-t