简体   繁体   English

C#.net助记符和一般用法

[英]C# .net Mnemonics and use in general

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. 我刚开始使用C#,在我看来,Microsoft叫他们的新系统.Net是因为您必须使用Internet来查找所有内容以查找有用的功能以及将它们放置在哪个类中。

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 ? 那就是为什么我不能使用Write或WriteLine代替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#. 然后,当我开始习惯所使用的对象(例如字符串)知道如何执行我习惯于使用外部函数来实现(例如上,下,子字符串等)的操作时,它们会更改规则数字,由于某种原因,数字不知道如何将自己从一种数字类型转换为另一种数字类型,相反,您必须调用Convert类静态函数将double更改为int,而调用Math类静态函数以实现舍入和截断。快速将您的简单(其他语言)语句转换为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. 如果您希望在没有显式的Casting,Conversions或ToStringing的情况下选择上下文驱动的类型(这似乎是C#中完成所有工作的基本必要),那将是很好的选择。

So... Is it even possible to write meaningful code in notepad and use cl with out Internet access? 所以...甚至有可能在记事本中编写有意义的代码并在没有Internet访问的情况下使用cl? 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? 有什么建议可以简化这种语言的使用过程并更自然地使用它?

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. 我不同意MS的观点,即字符串知道应该如何将自身转换为另一种类型,而其他数据类型(如ints)却不这样,因此,MS并不一致。 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). (您可以使用Convert类将类型转换为其他类型)。 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. 但是,.NET中的每个类型确实都有一个ToString()方法,但是,您不应该依赖该方法将所需的内容转换为字符串。

I think you have never worked in an OO language before, and therefore, you're having some difficulties with the paradigm shift. 我认为您以前从未使用过OO语言,因此,您在范式转换方面遇到了一些困难。 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. 一个类(如果设计得当)负责做一件事情,并且把一件事情做好。

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. SharpDevelop或Visual C#Express提供了以高效方式使用C#的功能。

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. 是的,与其他任何语言一样,C#也有缺点。 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. 这样可以更轻松地回答这些问题。

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 . 对于记事本,我没有有用的建议,但是我建议您使用免费的IDE之一,Microsoft Express EditionSharp Develop The IDE will speed the groking of the language, at which point, you can switch back to notepad. IDE将加快该语言的运行速度,此时,您可以切换回记事本。

Reading your post I was thinking that you worked mostly with C or dynamic languages previously. 阅读您的文章,我认为您以前主要使用C或动态语言。 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.) 也许C#对您来说是一个错误的选择,其中有IronPython,F#和其他一堆具有必要功能的语言(例如类外部的功能等)。

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. 实际上,.NET的某些组件之间存在很小的不一致,但是FW的大部分都是非常一致且可预测的。

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. 关于Internet /自动完成-我几乎无法想象任何不需要大量知识资源的.NET大小的技术。

Programming in c# using notepad is like buying a ferrari to drive in dirt roads. 使用记事本在C#中进行编程就像购买一辆法拉利在泥泞的道路上行驶一样。

At least use Visual Studio Express Edition. 至少使用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. 对于您写的内容,我了解您来自非OO背景,请尝试学习OO概念并尝试使用它。 You will eventually understand most design decisions made for .Net. 您最终将了解为.Net做出的大多数设计决策。

http://en.wikipedia.org/wiki/Object-oriented_programming http://zh.wikipedia.org/wiki/面向对象的编程

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. 哦,男孩,我从哪里开始(这将是一篇漫长的文章哈哈哈),好吧,一点一点地放手:“ Microsoft之所以叫他们的系统.NET,是因为您必须使用Intenet ...”,之所以被称为。 NET是因为Microsoft语言套件(现在还有其他一些软件,例如Phyton和Ruby等)也可以调用任何库或DLL,例如,您可以“ NET”(网络或调用)在Visual Basic,F#中内置的DLL。 ,来自WITHIN C#或任何其他语言的C ++,您也可以调用(或“ .NET”)C#库。 OK ONE DOWN!!! OK一下来!

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 ?". 下一个:“要求....使其类也不能用作其名称空间似乎很荒谬”,这是因为命名空间可以按您希望的那样具有许多类,而您的问题是:“这就是为什么不能我使用Write或WriteLine代替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: 原因是因为:“ Console”(System.Console在程序的开头加上了“ Using”语句)命名空间是“ Write”和“ WriteLine”生存的地方!(您也可以完全限定它(或“调用它”) ()。(在我看来,所有这些似乎都需要学习C#语法),好吧,下一步:

"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. “当我开始习惯于对象的想法时……”,用简单的词就可以了:C#是一种“严格类型安全的语言”,因此应该(应该)告诉您“您将要进入”的含义,否则请保持使用PHP或C之类的“弱或无类型的安全语言”,这并不意味着它是坏的,这意味着您要确保自己的工作,正如我告诉我的学生:“如果需要先定义然后再定义整数,编译器会为您执行此操作,否则您将有很多错误”,换句话说,在设计一套软件之前,您需要完成作业。

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). 注意:C#是隐式类型安全语言,因此,如果您希望以不安全的方式运行它,那么从那时开始,这将是确保您的工作,因此,以后当错误在运行时(很多时候)出现时,请不要抱怨(懒惰)。当客户已经在使用您糟糕的软件时)。

...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. Studio Express是免费的,甚至数据库SQL SERVER也是免费的!,除非您为一家公司工作,否则我会要求专业人士等。 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!!) 所有“额外”的东西都是针对大型公司,团队等的,您可以使用免费版本进行99%的工作(并且,如果要扩展到分布式软件或大型项目,您仍然可以购买更新到完整版本,或者如果您的软件大受欢迎,例如:如果您需要从数据库中每秒进行数百万次查询或命中,或者有100个人正在同一项目(代码)上工作,但大多数情况下是2或3个“正常”开发人员在家里或小型办公室工作,免费就可以了!)

cherrsss!!! cherrsss! (PS: Software Developer since the 80's) (PS:80年代以来的软件开发人员)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM