[LONG] C#对我来说太尖锐了 [英] [LONG] C# too sharp for me

查看:76
本文介绍了[LONG] C#对我来说太尖锐了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经厌倦了C#/ .NET过去三天我花了多少时间尝试将
放入数据库中。 C#将所有未初始化的

属性初始化为0(对于数字类型),直到C#2任何

的NULL概念。我一直想知道你们是如何在数据库顶部构建所有这些.NET

应用程序的。你猜怎么着?如果你没有
初始化一个DateTime(也许是因为你不想触摸它!)

你得到它infact初始化为{01/01/0001 0.00.00}但当然

当你试图把它放在一个SQLServer数据库中时你会收到这个错误:


SqlDateTime溢出。必须在1/1/1753 12:00:00 AM和

12/31/9999 11:59:59 PM


现在在C#2你可以选择将某些内容声明为

Nullable ...但它只是一个黑客(即使内置语言)和

使用Nullables可以防止你从做各种各样的事情和字符串

不能被声明为Nullable但至少它们被初始化

如果你不接触它们就会正确!


我昨天才明白什么是动态

语言的所有嗡嗡声,因为即使是Python业余爱好者,我仍然没有得到它

完全:我想将像Foo.Number这样的属性作为参数传递给

方法,我将不得不使用委托或匿名方法

(另一个新功能......而且,是的,你不能通过ref传递属性
http://msdn2.microsoft.com/en-us/library / w86s7x04 )他们告诉你

,你可以在任何地方使用它代表你的代表但不,不是

那里,而不是你需要的地方大多数或者可能带来奇怪的后果。

来自Jesse Liberty的引用Visual C#2005开发人员的笔记本

由O''Reilly发布:


< quote>

....如果我在匿名块中引用局部变量会怎样?

好​​问题。这可能会导致相当多的混乱,并且是一个自然的陷阱,特别是如果你不完全理解

后果。

C#允许在

匿名代码块的范围内捕获局部变量,然后在执行代码块

时访问它们。这可能会产生一些奇怪的副作用,例如在收集它们之后保持

对象。

< / quote>


好​​的属性不是字段/变量但请原谅我,如果我正在寻找

来实现我的问题的另一种解决方法。


现在你什么:如何不知道你传递的属性的类型

到这个函数,好吧,你必须使用泛型(

C#2的另一个新功能)。 ..而这一切都是为了做一些事情,在Python和Ruby中是

甚至没有问题......啊,我告诉你最好的事情吗? ADO.NET

这是你与.NET管理的数据库交谈的唯一机会

世界不支持Nullable类型:我偶然发现或者<毕竟,上帝仍然爱我,这是一种解决方法,因为微软确认没有解决方案,只有你想要传递的解决办法

a NULL值到SqlParameter。顺便说一下,我认为使用SqlClient你只需绕过ADO.NET并直接与SqlServer通话,如果你没有想要把你的脚和脚绑在SqlServer上。一个人必须自己编写
Nullable类型才能在C#v中使用NULL值.1

http://nullabletypes.sourceforge.net/

C#唯一有点动态的功能是Reflection,这是另一个

方式说内省,这是我认为的其中一项功能

甚至不需要在C#中学习我们给你所有的东西

of the the box world"但实际上由于.NET平台的价值很多,很方便。


嗯,我已经完成了...今天早上我买了Ruby编程的副本!


亚瑟

Man I''ve grown tired with C#/.NET the last three days I spent trying to
put a NULL value in a database. C# initializes all uninitialized
properties to 0 (for numeric types) and didn''t have until C# 2 any
concept of NULLs. I keep wondering how you guys built all these .NET
apps on the top of a database. And guess what? If you fail to
initialize a DateTime (maybe because you just don''t want to touch it!)
you get it infact initialized to {01/01/0001 0.00.00} but of course
when you try to put it in a SQLServer db you get this error in return:

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and
12/31/9999 11:59:59 PM

Now in C# 2 you have the option to choose to declare something as a
Nullable... but it''s just a hack (even if builtin the language) and
using Nullables prevents you from doing all sort of things, and strings
cannot be declared as Nullable but at least they are initialized
correctly if you don''t touch them!

I understood just yesterday what''s all the buzz around dynamic
languages since, even being a Python amateur, I still didn''t get it
fully: I wanted to pass a property like Foo.Number as a parameter to a
method and I would have to use a delegate or an anonymous method
(another new feature... and, yeah, you cannot pass a property by ref
http://msdn2.microsoft.com/en-us/library/w86s7x04) which they tell you
that you can use it everywhere you would use a delegate but no, not
there, not where you need it the most or maybe with odd consequences.
Quoting from Jesse Liberty "Visual C# 2005 a Developer''s Notebook"
published by O''Reilly:

<quote>
....what happens if I reference local variables in my anonymous block?
Good question. This can cause quite a bit of confusion and is a natural
trap to fall into, especially if you don''t fully understand the
consequences.
C# allows local variables to be captured in the scope of the
anonymous code block, and then they are accessed when the code block
is executed. This can create some odd side effects, such as keeping
objects around after they might otherwise have been collected.
</quote>

Ok properties are not fields/variables but pardon me if I was looking
to implement yet another workaround to my problem.

And you now what: how about not knowing the type of a property you pass
to this function, well, you gotta use a generic (another new feature of
C#2)... and all this for doing somethinig that in Python and Ruby is
not even a problem... ah and did I tell you the best thing? ADO.NET
which is your only chance to talk to a database in the .NET managed
world doesn''t support Nullable types: I found maybe by chance or
because, after all, god still loves me, a workaround since as Microsoft
confirmed there are no solutions, only workarounds if you want to pass
a NULL value to a SqlParameter. BTW I thought that using SqlClient you
would just bypass ADO.NET and talk directly to SqlServer if you didn''t
mind tying you hands and foots to SqlServer. A guy had to write
Nullable types himself to use NULL values in C# v. 1
(http://nullabletypes.sourceforge.net/)

The only kinda dynamic feature of C# is Reflection which is another
way to say introspection which is one of those features I thought I
would never need even to learn in the C# "we give you everything out
of-the-box world" but actually comes handy in many places due to the
_limitations_ of the .NET platform.

Well, I''m done... this morning I bought a copy of Programming Ruby!

Arthur

推荐答案

不要太苛刻但是再见。


你应该给Perl一个机会。对于小型小型实用程序,它是最快最精彩的语言

。这是一种非打字的,程序化的,易于阅读,易于编写(如果你知道你在做什么)的语言。


试一试。 ''null''意味着什么。

http:// www。 activestate.com/

ar ******* *****@gmail.com 写道:
Not to be too harsh, but bye.

You should give Perl a shot. Its the fastest most wonderful language
for small little utility programs. It is a non-typed, procedural
easy-to-read, easy-to-write (if you know what you''re doing) language.

give it a try. ''null'' means something there.

http://www.activestate.com/

ar************@gmail.com wrote:
我已经厌倦了C#/ .NET过去三天我花了很多时间试图把它变成NULL数据库中的值。 C#将所有未初始化的
属性初始化为0(对于数字类型),并且在C#2任何
NULL概念之前都没有。我一直想知道你们是如何在数据库顶部构建所有这些.NET
应用程序的。你猜怎么着?如果你没有初始化DateTime(也许是因为你只是不想触摸它!)
你得到它infact初始化为{01/01/0001 0.00.00}但当然<当你试图把它放在一个SQLServer数据库中时,你会收到这个错误:

SqlDateTime溢出。必须在1/1/1753 12:00:00 AM和
12/31/9999 11:59:59 PM

现在在C#2你可以选择申报作为一个Nullable的东西...但它只是一个黑客(即使内置语言)和
使用Nullables阻止你做各种事情,而字符串
不能声明为Nullable,但至少如果你不碰它们,它们会被正确初始化

我昨天才明白,自从动态
语言以来,所有这些都是嗡嗡声,即使是一个Python业余爱好者,我仍然没有完全得到它
:我想将像Foo.Number这样的属性作为参数传递给
方法,我将不得不使用委托或者一个匿名的方法
(另一个新功能......是的,你不能通过参考传递一个属性
http://msdn2.microsoft.com/en-us/library/w86s7x04 )他们告诉你
你可以使用在任何地方你都会使用代表,但不是,不是
那里,不是你最需要的地方,也可能是奇怪的后果。
引自Jesse Liberty的Visual C#2005开发者的笔记本
由O'Reilly出版:

< quote>
...如果我在匿名块中引用局部变量会怎样?
好问题。这可能会导致相当多的混乱,并且是一个自然陷入的陷阱,特别是如果你不完全理解后果。
C#允许在本地变量中捕获局部变量。
匿名代码块的范围,然后在执行代码块时访问它们。这可能会产生一些奇怪的副作用,例如在它们可能被收集之后保持它们周围。
< / quote>

好的属性不是字段/变量但是请原谅我是否正在为我的问题实施另一种解决方法。

你现在知道:怎么不知道你传递的属性的类型
到这个功能好吧,你必须使用一个通用的(另一个新的功能,即C#2)...而这一切都是为了做一些事情,在Python和Ruby中甚至不是一个问题......啊,做了我告诉你最好的事情? ADO.NET
这是你在.NET管理世界中与数据库交谈的唯一机会吗?不支持Nullable类型:我发现可能偶然或者
因为毕竟,上帝仍然爱我,一个解决方法,因为微软确认没有解决方案,只有你想要将一个NULL值传递给SqlParameter的解决方法。 BTW我认为使用SqlClient你只是绕过ADO.NET并直接与SqlServer交谈,如果你没有想到把你的脚和脚绑在SqlServer上。一个人必须自己编写Nullable类型才能在C#v中使用NULL值。
http://nullabletypes.sourceforge.net/

C#唯一有点动态的特性就是Reflection,这是另一种说内省的方式。那些我认为我甚至不需要在C#中学习的功能我们为你提供了所有的东西。但是由于.NET平台的存在,实际上很多地方都很方便。

好吧,我已经完成了...今天早上我买了一份Ruby编程! br />
Arthur
Man I''ve grown tired with C#/.NET the last three days I spent trying to
put a NULL value in a database. C# initializes all uninitialized
properties to 0 (for numeric types) and didn''t have until C# 2 any
concept of NULLs. I keep wondering how you guys built all these .NET
apps on the top of a database. And guess what? If you fail to
initialize a DateTime (maybe because you just don''t want to touch it!)
you get it infact initialized to {01/01/0001 0.00.00} but of course
when you try to put it in a SQLServer db you get this error in return:

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and
12/31/9999 11:59:59 PM

Now in C# 2 you have the option to choose to declare something as a
Nullable... but it''s just a hack (even if builtin the language) and
using Nullables prevents you from doing all sort of things, and strings
cannot be declared as Nullable but at least they are initialized
correctly if you don''t touch them!

I understood just yesterday what''s all the buzz around dynamic
languages since, even being a Python amateur, I still didn''t get it
fully: I wanted to pass a property like Foo.Number as a parameter to a
method and I would have to use a delegate or an anonymous method
(another new feature... and, yeah, you cannot pass a property by ref
http://msdn2.microsoft.com/en-us/library/w86s7x04) which they tell you
that you can use it everywhere you would use a delegate but no, not
there, not where you need it the most or maybe with odd consequences.
Quoting from Jesse Liberty "Visual C# 2005 a Developer''s Notebook"
published by O''Reilly:

<quote>
...what happens if I reference local variables in my anonymous block?
Good question. This can cause quite a bit of confusion and is a natural
trap to fall into, especially if you don''t fully understand the
consequences.
C# allows local variables to be captured in the scope of the
anonymous code block, and then they are accessed when the code block
is executed. This can create some odd side effects, such as keeping
objects around after they might otherwise have been collected.
</quote>

Ok properties are not fields/variables but pardon me if I was looking
to implement yet another workaround to my problem.

And you now what: how about not knowing the type of a property you pass
to this function, well, you gotta use a generic (another new feature of
C#2)... and all this for doing somethinig that in Python and Ruby is
not even a problem... ah and did I tell you the best thing? ADO.NET
which is your only chance to talk to a database in the .NET managed
world doesn''t support Nullable types: I found maybe by chance or
because, after all, god still loves me, a workaround since as Microsoft
confirmed there are no solutions, only workarounds if you want to pass
a NULL value to a SqlParameter. BTW I thought that using SqlClient you
would just bypass ADO.NET and talk directly to SqlServer if you didn''t
mind tying you hands and foots to SqlServer. A guy had to write
Nullable types himself to use NULL values in C# v. 1
(http://nullabletypes.sourceforge.net/)

The only kinda dynamic feature of C# is Reflection which is another
way to say introspection which is one of those features I thought I
would never need even to learn in the C# "we give you everything out
of-the-box world" but actually comes handy in many places due to the
_limitations_ of the .NET platform.

Well, I''m done... this morning I bought a copy of Programming Ruby!

Arthur



我希望看到那些具有事务支持的组件,并带有

对象池支持和一个用ruby构建的事件机制

和perl


问候

I would like to see those components with transaction support, with
object pooling support and an event mechanism that are built in ruby
and perl

Regards


在2005-09-24, ar ************ @ gmail。 com < ar ************ @ gmail.com>写道:
On 2005-09-24, ar************@gmail.com <ar************@gmail.com> wrote:
我已经厌倦了C#/ .NET过去三天我试图在数据库中放置一个NULL值。


恕我直言,在一个相当简单的程序上花了三天时间,比如语言更多关于你的话。

C#将所有未初始化的
属性初始化为0(对于数字类型),直到C#2任何
NULL概念都没有。


值类型的存在本质上是一个性能与易于使用的问题。与编程中的大多数权衡一样,对于某些问题域而言,选择是b / b
是一个不错的选择,而不是其他问题域的最佳选择。


不同意C#在这里做出的选择没有错。

然而,你帖子的语气意味着你不明白

选择,或者你认为语言设计者不理解

他们。大多数C#程序员,当然还有语言设计师,确实了解所做出的选择以及制作原因,了解这些选择的好处和不利之处,并且更喜欢C#

的做事方式。

我一直想知道你们是如何在数据库顶部构建所有这些.NET
应用程序的。


特殊情况下的null类型,并封装特殊情况..

猜猜是什么?如果你没有初始化DateTime(也许是因为你只是不想触摸它!)
你得到它infact初始化为{01/01/0001 0.00.00}但当然<当你试图把它放在一个SQLServer数据库中时,你会收到这个错误:

SqlDateTime溢出。必须在1/1/1753 12:00:00 AM和/ / 12/31/9999 11:59:59 PM


你做错了什么而不是默默地做错事

系统大声宣告错误。那是一件好事。

现在在C#2中,您可以选择将某些内容声明为可以为空的......但它只是一个黑客(即使是内置的)语言)和
使用Nullables阻止你做各种事情,并且字符串
不能被声明为Nullable,但至少如果你不碰它们就会正确初始化


我昨天才明白什么是关于动态语言的所有嗡嗡声,因为即使是一个Python爱好者,我仍然没有完全得到它



Python是一种非常好的语言。

我想把像Foo.Number这样的属性作为参数传递给
方法我必须要使用委托或匿名方法
(另一个新功能......并且,是的,你不能通过ref传递属性
http://msdn2.microsoft.com/en-us/library/w86s7x04


特性es不是字段,它们是功能上的语法糖。大多数

C#开发人员都明白这一点。我必须承认,我不相信

想要通过引用传递字段的设计。但是,一旦你理解了

他们的功能,可能是一个简单的界面会做你想要的



他们告诉你
你可以在任何地方使用它,但是不会,不是
那里,不是你最需要的地方,或者可能带来奇怪的后果。
来自Jesse Liberty的引用Visual C#2005开发人员的笔记本由O''Reilly出版:

< quote>
...如果我引用局部变量会发生什么我的匿名封锁?
好问题。这可能会导致相当多的混乱,并且是一个自然陷入的陷阱,特别是如果你不完全理解后果。
C#允许在本地变量中捕获局部变量。
匿名代码块的范围,然后在执行代码块时访问它们。这可能会产生一些奇怪的副作用,例如在它们可能被收集之后保持周围的物体。
< / quote>


闭包非常非常强大且非常非常复杂。这是另一个

自然权衡。

好​​的属性不是字段/变量但请原谅我,如果我正在寻找另一个解决办法来实现我的问题。

你现在知道:如何不知道你传递给这个功能的属性的类型,嗯,你必须使用通用(另一个新功能
C#2)......所有这些都是为了做一些事情,在Python和Ruby中甚至不是问题...


静态与动态类型是一个令人着迷的主题,以及一个充满辩论的主题。智能形式的辩论沿着我发现x语言的解决方案更优雅,因为
动态打字的b $ b。不那么聪明的辩论形式沿着我不能弄清楚如何用静态类型的语言做x,我不知道如何用静态类型的语言做x,我更喜欢关闭编译器检查。

啊我告诉你最好的事情吗? ADO.NET
这是你在.NET管理世界中与数据库交谈的唯一机会吗?不支持Nullable类型:我发现可能偶然或者
因为毕竟,上帝仍然爱我,一个解决方法,因为微软确认没有解决方案,只有你想要将一个NULL值传递给SqlParameter的解决方法。 BTW我认为使用SqlClient你只是绕过ADO.NET并直接与SqlServer交谈,如果你没有想到把你的脚和脚绑在SqlServer上。一个人必须自己编写Nullable类型才能在C#v中使用NULL值。
http://nullabletypes.sourceforge.net/

C#唯一有点动态的特性就是Reflection,这是另一种说内省的方式。那些我认为我甚至不需要在C#中学习的功能我们为你提供了所有的东西。但由于.NET平台的
_limitations_,实际上在很多地方都很方便。


这对我来说非常有趣。就个人而言,我在.Net中唯一一次使用

反射就是当我要么明确做某种

汇编/代码分析时(FxCop-type)东西)或在运行时动态加载
程序集。对于普通任务,我可以不用它。


OTOH,我做了很多VB.Net工作,VB程序员总是问我

关于反思,因为他们的设计需要某种类型的后期绑定。这些设计并非*必然*更糟,但是它们不会很好地适应工具集,而恕我直言所选择的工具集将会支持

必须有一些对设计过程有一定影响。


好​​吧,实际上这些设计通常都很糟糕。但我认为那是'b
因为那些不能适应新环境的程序员往往也是不好的代码设计师。
$ b $嗯,我已经完成了...今天早上我买了一份Ruby编程!


Ruby也是一种非常好的语言,可能会更适合你的风格

。然而,能够理解C#的做事方式

将使你受益,即使是作为Ruby的开发人员,就像理解这样做一样,Ruby的做事方式会使C#程序员受益。接受我只是无法理解语言X做事的方式的理念......
如果你真的有兴趣改善你的话,那么
是一种危险的心态

开发技巧。

亚瑟
Man I''ve grown tired with C#/.NET the last three days I spent trying to
put a NULL value in a database.
IMHO, spending three days on a fairly simple procedure like that says
much more about you than the language.
C# initializes all uninitialized
properties to 0 (for numeric types) and didn''t have until C# 2 any
concept of NULLs.
The existence of value types is essentially a performance vs. ease of
use issue. As with most trade-offs in programming, the choice that was
made is a good choice for some problem domains and not the optimal
choice for other problem domains.

There''s nothing wrong with disagreeing with the choices C# made here.
However, the tone of your post implies that you don''t understand the
choices, or that you think the language designers didn''t understand
them. Most C# programmers, and certainly the language designers, do
understand the choices made and why they were made, understand many
of the benefits and detriments of those choices, and prefer the C#
way of doing things.
I keep wondering how you guys built all these .NET
apps on the top of a database.
You special-case the null type, and encapsulate the special cases..
And guess what? If you fail to
initialize a DateTime (maybe because you just don''t want to touch it!)
you get it infact initialized to {01/01/0001 0.00.00} but of course
when you try to put it in a SQLServer db you get this error in return:

SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and
12/31/9999 11:59:59 PM
You did something wrong and instead of silently doing the wrong thing
the system loudly proclaimed the error. That''s a Good Thing.
Now in C# 2 you have the option to choose to declare something as a
Nullable... but it''s just a hack (even if builtin the language) and
using Nullables prevents you from doing all sort of things, and strings
cannot be declared as Nullable but at least they are initialized
correctly if you don''t touch them!

I understood just yesterday what''s all the buzz around dynamic
languages since, even being a Python amateur, I still didn''t get it
fully:
Python is a very nice language.
I wanted to pass a property like Foo.Number as a parameter to a
method and I would have to use a delegate or an anonymous method
(another new feature... and, yeah, you cannot pass a property by ref
http://msdn2.microsoft.com/en-us/library/w86s7x04)
Properties aren''t fields, they''re syntactic sugar over functions. Most
C# developers understand this. I must admit, I distrust a design that
would want to pass a field by reference. However, once you do understand
that they''re functions, it may be that a simple interface would do what
you want.
which they tell you
that you can use it everywhere you would use a delegate but no, not
there, not where you need it the most or maybe with odd consequences.
Quoting from Jesse Liberty "Visual C# 2005 a Developer''s Notebook"
published by O''Reilly:

<quote>
...what happens if I reference local variables in my anonymous block?
Good question. This can cause quite a bit of confusion and is a natural
trap to fall into, especially if you don''t fully understand the
consequences.
C# allows local variables to be captured in the scope of the
anonymous code block, and then they are accessed when the code block
is executed. This can create some odd side effects, such as keeping
objects around after they might otherwise have been collected.
</quote>
Closures are very, very powerful and very, very complex. That''s another
natural trade-off.
Ok properties are not fields/variables but pardon me if I was looking
to implement yet another workaround to my problem.

And you now what: how about not knowing the type of a property you pass
to this function, well, you gotta use a generic (another new feature of
C#2)... and all this for doing somethinig that in Python and Ruby is
not even a problem...
Static vs. dynamic typing is a fascinating subject, and one that is the
subject of much debate. Intelligent forms of the debate run along the
lines of "I find the solution to x more elegant in language y because
of dynamic typing". Less intelligent forms of the debate run along the
lines of "I can''t figure out how to do x in a statically-typed language,
I''d prefer to turn off compiler checks".
ah and did I tell you the best thing? ADO.NET
which is your only chance to talk to a database in the .NET managed
world doesn''t support Nullable types: I found maybe by chance or
because, after all, god still loves me, a workaround since as Microsoft
confirmed there are no solutions, only workarounds if you want to pass
a NULL value to a SqlParameter. BTW I thought that using SqlClient you
would just bypass ADO.NET and talk directly to SqlServer if you didn''t
mind tying you hands and foots to SqlServer. A guy had to write
Nullable types himself to use NULL values in C# v. 1
(http://nullabletypes.sourceforge.net/)

The only kinda dynamic feature of C# is Reflection which is another
way to say introspection which is one of those features I thought I
would never need even to learn in the C# "we give you everything out
of-the-box world" but actually comes handy in many places due to the
_limitations_ of the .NET platform.
This is pretty interesting to me. Personally, the only time I''ve used
reflection in .Net is when I''m either explicitly doing some kind of
assembly/code analysis (FxCop-type stuff) or when dynamically loading
assemblies at runtime. For ordinary tasks, I could do without it.

OTOH, I do a lot of VB.Net work, and VB programmers are always asking me
about reflection because they''ve got a design that requires some type
of late binding. These designs aren''t *necessarily* worse, but they
don''t fit the toolset well, and IMHO the chosen toolset is going to
have to have some sort of effect on the design process.

OK, actually these designs are usually pretty bad. But I think that''s
because programmers who can''t adapt to new environments tend to be
bad code designers as well.
Well, I''m done... this morning I bought a copy of Programming Ruby!
Ruby is a very nice language as well, and may fit your style a bit
better. However, being able to understand the C# way of doing things
will benefit you even as a Ruby developer, just as understanding the
Ruby way of doing things would benefit C# programmers. Accepting the
mindset of "I just couldn''t understand the way language X does things"
is a dangerous mindset if you''re truly interested in improving your
development skills.

Arthur



这篇关于[LONG] C#对我来说太尖锐了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆