如何将C#代码更改为VB.NET请帮帮我 [英] How do I change C# code to VB.NET please help me

查看:80
本文介绍了如何将C#代码更改为VB.NET请帮帮我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            string tabName = (sender as Button).CommandParameter.ToString();
 
            var item = tabDynamic.Items.Cast<TabItem>().Where(i => i.Name.Equals(tabName)).SingleOrDefault();
 

            TabItem tab = item as TabItem;
 
            if (tab != null)
            {
                if (_tabItems.Count < 3)
                {
                    MessageBox.Show("Cannot remove last tab.");
                }
                else if (MessageBox.Show(string.Format("Are you sure you want to remove the tab '{0}'?", tab.Header.ToString()),
                    "Remove Tab", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    // get selected tab
                    TabItem selectedTab = tabDynamic.SelectedItem as TabItem;
 
                    // clear tab control binding
                    tabDynamic.DataContext = null;
 
                    _tabItems.Remove(tab);
 
                    // bind tab control
                    tabDynamic.DataContext = _tabItems;
 
                    // select previously selected tab. if that is removed then select first tab
                    if (selectedTab == null || selectedTab.Equals(tab))
                    {
                        selectedTab = _tabItems[0];
                    }
                    tabDynamic.SelectedItem = selectedTab;
                }
            }
        }
    }
}





我尝试了什么:



我想在VB.net中使用C#代码,如上所述,请帮助我



What I have tried:

I want to use C# code in VB.net as above please some one help me

推荐答案

您不能在单个项目中混合使用语言,但无论您使用何种语言编写,都可以引用程序集。

但您可以使用自动翻译程序在它们之间进行转换:代码转换器 [ ^ ]不太糟糕。请注意,它可能无法正确使用,因此在测试时应该真正理解这两种语言,并注意除非该代码的来源针对相同的环境,否则您的代码可能根本不起作用。 br />


一般来说,编写自己的代码比依靠互联网上的代码并进行翻译更好。
You can't mix languages within a single project, although you can reference Assemblies regardless of what language they were written in.
But you can use automated translators to convert between them: Code Converter[^] isn;t too bad. Be aware that it may not get it right, so you should really understand both languages when you test this, and be aware that unless the "source" of that code is targeting the same environment your code is that may not work at all.

Generally speaking, you are better off writing your own code than relying on code you found on the internet and translating it.


这篇关于如何将C#代码更改为VB.NET请帮帮我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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