zoukankan      html  css  js  c++  java
  • VB改写C#

    1.VB的Val()函数

    先从程序集中引入Microsoft.VisualBasic命名空间。
    不过,即便是引入了Microsoft.VisualBasic命名空间,还是不能直接使用像Val()这样的函数名,而要加上类名。
    Val函数位于Conversion类中,这个类(在VB中是Module)中定义了Val、Hex、Str、Oct、Int、Fix等函数。
    具体哪个函数在哪个类里可以在对象浏览器里看,最快捷的方法是在VB.NET环境中使用右键菜单中的“转到定义”。
                // 引用Microsoft.VisualBasic程序集
               // 并 using Microsoft.VisualBasic;
                int a = (int)Conversion.Val("123abc"); 
                Console.WriteLine(a);  // 输出123
                Console.ReadKey();            

    2.VB中Right(x,n)

    在VB中的使用:

       利用 Right 函数从字符串右边返回指定数目的字符:
       Dim AnyString, MyStr
       AnyString = "Hello World"       ''定义字符串。
       MyStr = Right(AnyString, 1)     ''返回 "d"。
       MyStr = Right(AnyString, 6)     '' 返回 " World"。
       MyStr = Right(AnyString, 20)    '' 返回 "Hello World"。

    在C#中Substring方法可以实现相关功能:

    首先我们回顾一下Substring方法。

    用法一: String.Substring 方法 (startIndex, length) 

    返回此String中从 startIndex 开始的长度为 length 的子字符串。

    startIndex:子字符串的起始位置的索引,从0开始。 

    length:子字符串中的截取字符数

    用法二:String.Substring方法 (startIndex)

    返回此String中从 startIndex 开始的,截取之后余下所有字符。

    startIndex:子字符串的起始位置的索引,从0开始。

    熟悉了此方法后,我们来实现如何实现左截取和右截取字符串。

    左截取:str.Substring(0,i) 返回,返回左边的i个字符

    右截取:str.Substring(str.Length-i,i) 返回,返回右边的i个字符

    int i=2;
    string str=”123456″;
    string strLeft=str.Substring(0,i);
    string strRight=str.Substring(str.Length-i,i);
    strLeft为”12″
    strRight为”56″

    3.VB中Unload Me

    就是卸载自己(卸载当前窗体)
    你可以这样理解: 如果是ME.VISIBLE=FALSE 那么就是窗体隐藏,但是窗体时加载的(有些病毒就是这样在后台运行)。
    但是如果是UNLOAD就退出了加载(释放了系统资源),需要它的时候就又要重新加载。
    ME在一个窗体中使用就相当于窗体本身(比如窗体叫M.FRM, 那么ME就是M.FRM)

    C#
    this.Close();

    4.VB中Combobox.ListIndex等价于C# Combobox.SelectedIndex 

    5.C#中的 Form_Closed 事件 = VB中的 Form_Unload 事件
    C#中的 Form_Closing 事件 = VB中的 Form_QueryUnload 事件

    备注:VB中Cancel=1 是不会关闭窗体的意思

    private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
    DialogResult ddd=MessageBox.Show("您确定要关闭么?","警告",MessageBoxButtons.YesNo);
    if(ddd.ToString().Equals("Yes"))
    {
    e.Cancel=false;
    }
    else
    {
    e.Cancel=true;
    }
    }
    View Code
  • 相关阅读:
    Linux之文件处理命令
    Linux基础命令
    rip实验
    Linux基础之磁盘分区
    mysql安装
    centos Apache、php、mysql默认安装路径
    You probably tried to upload too large file. Please refer to documentation for ways to workaround this limit.
    Wrong permissions on configuration file, should not be world writable!
    机器会学习么 学习总结
    实验 5 Spark SQL 编程初级实践
  • 原文地址:https://www.cnblogs.com/congcongdi/p/8986081.html
Copyright © 2011-2022 走看看