C# .net 助记符和一般使用
我刚刚开始使用 C#,对我来说,微软似乎将他们的新系统称为 .Net,因为你必须使用 Internet 查找所有内容才能找到有用的函数以及他们将其隐藏在哪个类中。
对我来说,这似乎是无意义的要求编写和设计为独立的过程/函数(非实例化的静态对象),使其类不能充当其名称空间。
这就是为什么我不能使用 Write 或 WriteLine 而不是 Console.WriteLine ?
然后,当我开始习惯我正在使用的对象(如字符串)知道如何执行操作时,我习惯于使用外部函数来实现(如 upper、tolower、substring 等),它们会更改规则数字,出于某种原因,数字不知道如何将自己从一种数字类型转换为另一种数字类型,而是必须调用 Convert 类静态函数将 double 更改为 int 和 Math 类静态函数以实现舍入和截断..快速将简单的(其他语言中的)语句转换为 C# 中的无数字符行。
它似乎还痴迷于强类型,这在某种程度上干扰了我编码时的思维过程。 我知道类型安全可以减少错误,但我认为它也会增加复杂性,有时是不必要的。 如果您可以在不需要显式强制转换或转换或 ToStringing 的情况下选择上下文驱动类型,那就太好了,而显式强制转换或转换或 ToStringing 似乎是 C# 中完成任何操作的基本必要条件。
那么...是否有可能在记事本中编写有意义的代码并在没有互联网访问的情况下使用 cl ? 如果不借助自动完成和网络访问,您会使用什么参考书?
对于平滑掌握这种语言并更自然地使用它的过程有什么建议吗?
I'm just starting out with C# and to me it seems like Microsoft Called their new system .Net because you have to use the Internet to look everything up to find useful functions and which class they stashed it in.
To me it seems nonsensical to require procedure/functions written and designed to stand alone ( non instantiated static objects) to have their class not also function as their namespace.
That is Why can't I use Write or WriteLine instead of Console.WriteLine ?
Then when I start to get used to the idea that the objects I am using ( like string) know how to perform operations I am used to using external functions to achieve ( like to upper, tolower, substring, etc) they change the rules with numbers, numbers don't know how to convert themselves from one numeric type to another for some reason, instead you have to invoke Convert class static functions to change a double to an int and Math class static functions to achieve rounding and truncating.. which quickly turns your simple( in other languages) statement to a gazillion character line in C#.
It also seems obsessed with strong typing which interferes somewhat with the thought process when I code. I understand that type safety reduces errors , but I think it also increases complexity, sometimes unnecessarily. It would be nice if you could choose context driven types when you wish without the explicit Casting or Converting or ToStringing that seems to be basic necessity in C# to get anything done.
So... Is it even possible to write meaningful code in notepad and use cl with out Internet access? What ref book would you use without recourse to autocomplete and Network access?
Any suggestions on smoothing the process towards grokking this language and using it more naturally?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我认为您因为多年来习惯以一种方式工作而感到有点痛苦,现在必须花时间让自己适应在新平台中使用/开发。
我不同意你的观点,即 MS 在字符串知道如何将自身转换为另一种类型这一事实上并不一致,而其他数据类型(如整数)则不知道。
这是不正确的,因为字符串本身也不知道如何将它们转换为另一种类型。 (您可以使用 Convert 类将类型转换为其他类型)。
然而,.NET 中的每种类型确实都有一个 ToString() 方法,但是,您不应该依赖该方法将您拥有的任何内容转换为字符串。
我认为您以前从未使用过面向对象语言,因此,您在范式转换方面遇到了一些困难。
可以这样想:一切都与责任和行为有关。 一个类(如果设计得很好)负责做一件事,并且把这件事做好。
I think you're suffering a bit from the fact that you've used to working in one way during some years, and now must take time to get yourself comfortable using / developing in a new platform.
I do not agree with you , that MS hasn't been consistent on the fact that a string knows how it should convert itself to another type, and other datatypes (like ints) do not.
This is not true, since strings do not know for themselves how they should be converted to another type as well. (You can use the Convert class to Convert types to other types).
It is however true that every type in .NET has a ToString() method, but, you should not rely on that method to convert whatever you have to a string.
I think you have never worked in an OO language before, and therefore, you're having some difficulties with the paradigm shift.
Think of it this way: it's all about responsabilities and behaviour. A class is (if it is well designed) responsible for doing one thing, and does this one thing good.
没有理由使用记事本来编写现代语言的代码。 SharpDevelop 或 Visual C# Express 提供了以高效方式使用 C# 的功能。
不,由于复杂性,不使用互联网作为信息来源也不是一个好的选择。
您可以购买一本以结构化方式向您介绍该语言概念的书,但要获取最新信息,互联网是必要的。
是的,与任何其他语言一样,C# 也有缺点。 我只能给你一些习惯语言的建议。 在那之后,许多缺点就变得可以理解了,即使其中一些缺点并没有变得不那么烦人。 如果您想了解某些语言构造如何工作或如何更有效地解决特定问题,我建议您使用示例代码提出清晰、直接的问题。 这使得回答这些问题变得更容易。
There is no excuse to use notepad to code a modern language. SharpDevelop or Visual C# Express provide the functionality to work with C# in a productive way.
And no, due to the complexity, not using the internet as a source of information is also not a good option.
You could buy a book that introduces you to the concepts of the language in a structured way, but to get up-to-date information, the internet is neccessary.
Yes, there are drawbacks in C#, like in any other language. I can only give you the advice to get used to the language. Many of the drawbacks become understandable after that, even if some of them don't become less annoying. I recommend that you ask clear, direct questions with example code if you want to know how some language constructs work or how you can solve specific problems more efficiently. That makes it easier to answer those questions.
对于记事本,我没有任何有用的建议,但是我建议您使用免费的 IDE 之一,Microsoft 的 Express 版本,或Sharp Develop。
IDE 将加快语言的掌握速度,此时,您可以切换回记事本。
For notepad, I have no useful advice, however I would advise you to use one of the free IDE's, Microsofts Express Editions, or Sharp Develop.
The IDE will speed the groking of the language, at which point, you can switch back to notepad.
阅读您的文章,我认为您以前主要使用 C 或动态语言。 也许 C# 对你来说只是一个错误的选择,IronPython、F# 和许多其他语言都有必要的功能(比如类之外的函数等),
我不同意你关于一致性的观点。 事实上.NET的一些组件之间存在着小的不一致,但是FW的大部分是非常一致和可预测的。
强类型是低缺陷数的一个重要因素。 动态类型在小型/中型项目(如脚本等)中表现良好。 在或多或少复杂的程序中,动态性可能会带来很多复杂性。
关于互联网/自动完成 - 我几乎无法想象任何具有 .NET 规模的技术不需要大量的知识源。
Reading your post I was thinking that you worked mostly with C or dynamic languages previously. Maybe C# is just a wrong choice for you, there are IronPython, F# and a bunch of other languages that have necessary functionality (like functions outside of classes etc.)
I disagree with you about consistency. In fact there are small inconsistency between some components of .NET, but most part of FW is very consistent and predictable.
Strong typing is a huge factor in low defect count. Dynamic typing plays nice in small/intermediate projects (like scripts, etc). In more or less complex program dynamism can introduce a lot of complexity.
Regarding internet/autocomplete - I can hardly imagine any technology with size of .NET that doesn't require a lot of knowledge sources.
使用记事本进行 C# 编程就像购买一辆法拉利在土路上行驶一样。
至少使用 Visual Studio Express 版本。 对于你写的内容,我知道你来自非面向对象的背景,尝试学习面向对象的概念并尝试使用它。 您最终将了解为 .Net 所做的大多数设计决策。
http://en.wikipedia.org/wiki/Object-oriented_programming
Programming in c# using notepad is like buying a ferrari to drive in dirt roads.
At least use Visual Studio Express Edition. For what you wrote I understand that you come from a non OO background, try to learn the OO concept and try to use it. You will eventually understand most design decisions made for .Net.
http://en.wikipedia.org/wiki/Object-oriented_programming
噢,我该从哪里开始呢(这将是一篇很长的文章哈哈哈),好吧,让我们一点一点地开始:
“微软称他们的系统为.NET,因为你必须使用Intenet...”,之所以称为.NET,是因为微软语言套件(现在还有其他一些语言,如Phyton和Ruby等)可以调用任何库或 DLL,例如,您可以“NET”(网络或调用)从 C# 中的 Visual Basic、F#、C++ 中构建的 DLL,或者从任何这些语言中,您也可以调用(或“.NET”)C# 库。 好的,降一分!!!
下一个:“要求......让它们的类不充当它们的命名空间似乎是荒谬的”,这是因为命名空间可以拥有您希望的任意多个类,而您的问题:
“这就是为什么我不能使用 Write 或 WriteLine 而不是 Console.WriteLine ?”。
原因是因为:“Console”(System.Console hense在程序开头的“Using”语句)命名空间是“Write”和“WriteLine”所在的地方!!(您也可以完全限定它(或“调用它”) ”)。(在我看来,您需要学习 C# 语法),好的,下一步:
“当我开始习惯对象的想法时......”,好的,简单来说:
C# 是一种“强类型安全语言”,因此应该-必须告诉您“您正在进入”什么,否则请使用“弱或没有类型安全的语言”,例如 PHP 或 C 等。这并不意味着它是坏的只是意味着你的工作是确保,正如我告诉我的学生:“如果你需要一个整数,那么定义一个整数,而不是让编译器为你做,否则你将会有很多坏的错误”,或者换句话说,做你的设计软件之前的功课。
注意:C# 是隐式类型安全语言,所以如果您愿意,您可以将其运行为不安全的语言,因此从那时起,您的工作就是确保,所以当 bug 在运行时出现时(而且很多时候),不要抱怨(因为懒)当客户已经在使用你的蹩脚软件时)。
...最后但并非最不重要的一点是:为什么你想用记事本射击自己? Studio Express 是免费的,甚至数据库 SQL SERVER 也是免费的!!,除非您在公司工作,否则我会要求 PRO 等。 所有“额外”的东西都是针对大公司、团队等的,您可以使用免费版本完成 99% 的事情(一旦您想升级到分布式软件或大型项目,您仍然可以购买更新到完整版本,或者如果您的软件大受欢迎,例如:如果您需要从数据库每秒进行数百万次查询或点击,或者 100 人正在处理同一个项目(代码),但大多数情况下只有 2 或 3 个“普通”开发人员在家里或小办公室工作,免费的就足够了!!)
cherrsss!!! (PS:80年代以来的软件开发人员)
Oh boy where do i start with you(this will be a long post hahaha), well, lets go little by little:
"Microsoft called their system .NET because you have to use Intenet...", the reason why is called .NET is because the SUITE OF MICROSOFT LANGUAGUES(and now some other ones too like Phyton and Ruby, etc) CAN CALL ANY LIBRARY or DLLs, example you can "NET"(Network OR CALL) a DLL that was built in Visual Basic, F#, C++ from WITHIN C# or from any of those languagues you can also call(or ".NET") C# libraries. OK ONE DOWN!!!
NEXT ONE: "it seems nonsensical to require....to have their class not also function as their namespace", this is because a Namespace can have AS MANY CLASSES AS YOU WISH, and your question:
"That is Why can't I use Write or WriteLine instead of Console.WriteLine ?".
The reason is because: "Console"(System.Console hense the "Using" statement at the beginning of your program) Namespace is where "Write" and "WriteLine" LIVES!!(you can also FULLY qualify it (or "call It"). (all this seems to me that you need to study C# Syntax), ok NEXT:
"when I start to get used to the idea that the objects...", ok in simple words:
C# is a "Strongly Type-Safe language" so that SHOULD-MUST tell you what "you are getting in to" otherwise STAY WITH "WEAK or NO TYPE SAFE LANGUAGES" LIKE PHP or C , etc. this does NOT means is bad it just MEANS IS YOUR JOB TO MAKE SURE, as i tell my students: "IF YOU NEED AN INT THEN DEFINE AN INT INSTEAD LETTING THE COMPILER DO IT FOR YOU OTHERWISE YOU WILL HAVE A LOT OF BAD BUGS", or in other words do YOUR homework BEFORE DESIGNING A PIECE OF SOFTWARE.
Note: C# is IMPLICITY TYPE SAFE language SO IF YOU WANT YOU CAN RUN IT AS UNSAFE so from then it wiLL be your job to make sure, so dont complain later(for being lazy) when bugs arrive AT RUNTIME(and a lot of times when the customer is already using your crappy software).
...and last but not least : Whey do you wan to shoot yourself by using notepad? Studio Express is FREE, even the database SQL SERVER is FREE TOO!!, unless you work for a company I WILL ASK FOR PRO, ETC. all the "extra" stuff is for large companies, teams, etc, YOU CAN DO 99% OF THE STUFF WITH THE FREE VERSIONS(and you can still buy-update to full version once you want to scalate to Distributed Software or a Large Project, or if your software becomes a big hit, Example: if you need millions of queryes or hits PER SECOND from your database or 100 people are working on same project(code) but for the majority of times for 2 or 3 "normal" developers working at home or small office the FREE ONES ARE ENOuGH!!)
cherrsss!!! (PS: Software Developer since the 80's)