在C#中如何弄清楚属性和方法的组合以获得所需的结果? [英] In C# how to make out what combination of Properties and Methods to get desired results?

查看:56
本文介绍了在C#中如何弄清楚属性和方法的组合以获得所需的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我学到了所有基础知识和一些先进的C#和ASP.Net。我想知道经验丰富的开发人员如何确定用于获得问题的期望输出的属性/方法的组合(例如,要获得当前线程ID需要这样做:int n = System.Threading.Thread。 CurrentThread.ManagedThreadId;),你怎么知道怎么做到这个?它似乎非常棘手,必须使用属性和方法以及某些类的另一个属性来获取某些东西,你怎么知道这个(不是谷歌搜索!!)?我想开始编程而不是谷歌搜索,而是自己做。



在线程示例中,当我探索Thread类时发现ManagedThreadId和CurrentThread是它的方法但是在intelisense中,ManagedThreadId方法在'Thread'之后的第一个'。'运算符之后没有出现(也有一些其他的方法和属性),为什么会这样?



我使用VS2012作为我的开发环境。



谢谢,

Ramesh

Hi Everyone,

I have learned all the basics and a bit advanced C# and ASP.Net. I am wondering how experienced developers make out what combination of property/methods to be used to get the desired out put for a problem (for eg. To get the current thread ID need to do this: int n = System.Threading.Thread.CurrentThread.ManagedThreadId;), how will you make out how to get to this? it seems very tricky, one has to use properties and methods and again another properties of certain class to get something, how will you know this(Not googling!!)? I want to start programming by not googling but doing on my own.

And in the Threading example when I explored the Thread class found ManagedThreadId and CurrentThread are methods of it but in intelisense the ManagedThreadId method does not appear (also some other methods and properties) after the first '.' operator after 'Thread', why is that?

I am using VS2012 as my development environment.

Thank you,
Ramesh

推荐答案

Intellisense真正显示所有可访问的属性...并且 System.Threading.Thread.ManagedThreadId System.Threading.Thread.CurrentThreads 不是一个方法,它们是属性。而线程后跟点智能感知行为将取决于那个符号。它可以是类 System.Threading.Thread ,然后Intellisense将只显示静态成员,因为只有这些成员适用。但是你可以定义一个名为Thread的变量或类型成员(为什么不呢?在很多情况下这是相当推荐的),然后Intellisense将显示与此变量/成员相关的所有可访问成员。



没有什么可以回答的。这篇文章不是某个问题。您需要清楚目前您真正想要学习什么。这一次,你得到的建议和你要求的一样多。 :-)



-SA
All accessible properties are really shown by Intellisense... And System.Threading.Thread.ManagedThreadId and System.Threading.Thread.CurrentThreads are not exactly a method, they are properties. And "Thread" followed by dot Intellisense behavior will depends on what symbol is that. It can be the class System.Threading.Thread, then Intellisense will show only static members, because only such members are applicable. But you can define a variable or some type member called "Thread" (why not? in many cases this is rather recommended), and then Intellisense will show all accessible members relevant to this variable/member.

There is nothing really to answer. This post is not something like a certain question. You need to be clear about what do you really want to learn at the moment. This time, you got as much advice as you have asked for. :-)

—SA


这篇关于在C#中如何弄清楚属性和方法的组合以获得所需的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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