开发者

2 simple and quick C# specific Visual Studio questions?

开发者 https://www.devze.com 2023-04-12 14:27 出处:网络
Just a quick one really, I\'ve tried googling and searching through the visual studio tools but I seem to be having no luck, so I know I\'ll get a quick answer on here!

Just a quick one really, I've tried googling and searching through the visual studio tools but I seem to be having no luck, so I know I'll get a quick answer on here!

I've been developing in vb.net for a while using visual studio and just moved back to c# and I'm irritated by a few things that I'm sure just need a check box ticking or unticking somewhere.

Firstly, when I created an event in C# I have to write out the event and then add it to the markup code, in vb I used to be able to select the control from the top left drop down (when in code behind) and then select the event from the top right dropdown, this would automatically create the event for me and attach it to the control. I can't find the setting for this to be turned on!

Secondly, when I create classes in a sub folder, the namespace for that class is given the folder name as a sub namespace. I just want it to use the namespace of the project by default, it's just getting a bit annoying!

E.G.

My开发者_如何学PythonProject has MyProject namespace

MyProject --> MyFolder --> MyClass has the name space MyProject.MyFolder ....

Sorry for the outrageously basic question.

Regards


1) C# and VB handle event handler subscriptions quite differently so there is no direct equivilent of this in C#. You can do this by switching to the events tab of the properties window, and double clicking on the event you want to handle (in design view). From code view, simply type "myControl.EventIWantToHandle +=" and then double hit tab, which will generate the event handler method for you. The best place to do this is most likely in the constructor, right below the InitializeComponent call.

2) Highlight the folder in solution explorer, and in the properties window set the 'NamespaceProvider' property to false*

*It's actually a Best Practice™ for the folder stucture to match the namespace stucture - C# is helping you out by doing this (I'm a little surprised that VB doesn't)


  1. This isn't available in C#. If you want to add the event, you can do so from the designer. First select the control, view the events of the control in the Properties dialog, and then double-click the event name to create the code-behind.

  2. This is by design. Folders are intrinsically treated as hierarchies in your namespace.

Sorry you're frustrated, but believe me there are many advantages to learning C# over VB.NET.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号