草庐IT

final-class

全部标签

c# - 什么时候用什么时候不用 Try Catch Finally

我正在.net3.5中创建asp.netweb应用程序,我想知道何时使用以及何时不使用TryCatchFinallyblock?特别是,我的大部分trycatch都围绕着执行存储过程和填充文本字段或GridView?当您执行存储过程并填充数据显示控件时,您会EVERYTIME使用TryCatch吗?我的代码块通常是这样的:protectedvoidAddNewRecord(){try{//executestoredproc//populategridviewcontrolsortextboxes}catch(Exceptionex){//displayamessageboxtouser

c# - 通过反射仅获取当前类(class)成员

假设这段代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Reflection;namespaceTestFunctionality{classProgram{staticvoidMain(string[]args){//System.Reflection.Assembly.GetExecutingAssembly().LocationAssemblyassembly=Assembly.LoadF

C#/N 休眠 : Association references unmapped class

几个小时以来,我一直在努力解决这个NHibernate问题。我在网络和NHibernate文档上进行了广泛的研究,但我无法理解这个问题。我对NHibernate比较陌生,但很喜欢它。不过,在那种情况下,它让我发疯。我正在为网站编写一个小型“投票”模块。我有几个类(Poll、PollVote和PollAnswer)。主要的Poll是导致问题的原因。这就是类的样子:publicclassPoll{publicvirtualintId{get;set;}publicvirtualSiteSite{get;set;}publicvirtualstringQuestion{get;set;}pu

c# - cs0030 :Unable to generate a temporary class

我有一个Web服务,当我尝试生成它的对象时出现以下错误。"Unabletogenerateatemporaryclass(result=1).errorCS0030:Cannotconverttype'ShortSell.ShortSellRQOriginDestinationInformationFlightSegment[]'to'ShortSell.ShortSellRQOriginDestinationInformationFlightSegment'errorCS0030:Cannotconverttype'ShortSell.ShortSellRSOriginDestina

c# - 公共(public)静态字符串 MyFunc() 上的 "Expected class, delegate, enum, interface or struct"错误。什么 's an alternative to "字符串”?

当我尝试使用以下静态函数时出现错误。错误:Expectedclass,delegate,enum,interface,orstruct函数(和类):namespaceMyNamespace{publicclassMyClass{//SomeotherstaticmethodsthatuseClasses,delegates,enums,interfaces,orstructspublicstaticstringMyFunc(stringmyVar){stringmyText=myVar;//DosomestuffwithmyTextandmyVarreturnmyText;}}}这导致

c# - 在 try & catch 中返回与在 finally 中返回?

其中任何一个都有风险吗?一个更好吗?或者它是您打印出来并throw飞镖来决定的那些东西之一?既然我了解了finally的工作原理,我就想这样做:try{stuffthatchangessomething...}catch(System.Exceptionex){something.worked=false;something.err=ex.Message;}finally{stuff.close();returnsomething;}但我见过:try{stuffthatchangessomething...returnsomething;}catch(System.Exceptione

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# - .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# - Try-Catch-Finally 返回

这个问题在这里已经有了答案:WillcodeinaFinallystatementfireifIreturnavalueinaTryblock?(12个答案)关闭7年前。我有以下代码:publicDataTableGetAllActiveUsers(){DataTabledataTable=newDataTable();try{connection.Open();SqlCommandgetAllActiveUsersCommand=newSqlCommand(getAllUsers,connection);SqlDataAdapterdataAdapter=newSqlDataAdap

c# - 在 C# 中将参数作为 final 传递

这可能是一个重复的问题。但无法在搜索中找到它在java中,为了将方法参数标记为常量,我们将其声明为final等效的C#关键字是什么?喜欢publicvoiddoSomeThing(finalobjectmyObject){//printmyobject} 最佳答案 这在C#中是不可能的-无法将传入的参数标记为常量。如果您有一个const需要对许多函数可用,为什么不使用正确的作用域(类作用域或全局作用域,如果需要)声明它? 关于c#-在C#中将参数作为final传递,我们在StackOve