C和vbnet的转换

更新时间:2023-05-16 04:19:56 阅读: 评论:0

今天在看30个 学习必须收藏的的时候看到了这篇文章,感觉很好,以前都是自己看MSDN 然后自己比较,现在又了这个感觉方便多了,很值得收藏! 这个是原文地址:VB and C# Comparison 正文开始:
Program Structure  Comments  Data Types  Constants  Enumerations  Operators
Choices  Loops  Arrays  Functions  Strings
Regular Expressions
Exception Handling  Namespaces
Class / Interfaces  Constructors / Destructors  Using Objects  Structs
Properties  Upd ated!
Delegates / Events  Generics  New!
Console I/O  File I/O
V B.N E T  P r o g r a m  S t r u c t u r e
C #
Imports System
Namespace Hello    Class HelloWorld
母别子
Overloads Shared Sub Main (ByVal args() As String)
Dim name As String = "VB"
'See if an argument was pasd from the command line
If args.Length = 1 Then name = args(0)
Console.WriteLine("Hello, " & name & "!")
End Sub    End Class  End Namespace
using System;
namespace Hello {
怪兽大师
public class HelloWorld {
public static void Main (string[] args) {
string name = "C#";
// See if an argument
was pasd from the command line
if (args.Length == 1)              name = args[0];
Console.WriteLine("Hel lo, " + name + "!");        }    }  }
V B.N E T
C o m m e n t s
C #
' Single line only
REM Single line only
''' <summary>XML comments</summary>// Single line
/* Multiple
line  */
/// <summary>XML comments on single line</summary>
/** <summary>XML comments on multiple lines</summary> */
V B.N E T D a t a T y p e s C#
Value Types
Boolean
Byte, SByte
Char
Short, UShort, Integer, UInteger, Long, ULong Single, Double
Decimal
Date
Reference Types
Object
String
Initializing
Dim correct As Boolean = True
Dim b As Byte = &H2A 'hex or &O52 for octal Dim person As Object = Nothing
Dim name As String = "Dwight"
Dim grade As Char = "B"c
Dim today As Date = #12/31/2007 12:15:00 PM# Dim amount As Decimal = 35.99
Dim gpa As Single = 2.9!
Dim pi As Double = 3.14159265
Dim lTotal As Long = 123456L
Dim sTotal As Short = 123S
Dim usTotal As UShort = 123US
Dim uiTotal As UInteger = 123UI Value Types
bool
byte, sbyte
char
short, ushort, int, uint, long, ulong float, double
decimal
DateTime (not a built-in C# type)
Reference Types
object
string
Initializing
bool correct = true;
byte b = 0x2A; // hex
object person = null;
string name = "Dwight";
char grade = 'B';
DateTime today =
海南美景DateTime.Par("12/31/2007 12:15:00"); decimal amount = 35.99m;
float gpa = 2.9f;
double pi = 3.14159265;
long lTotal = 123456L;
short sTotal = 123;
ushort usTotal = 123;
Dim ulTotal As ULong = 123UL Implicitly Typed Local Variables
Dim s = "Hello!"
Dim nums = New Integer() {1, 2, 3}
Dim hero = New SuperHero With {.Name = "Batman"}
Type Information
Dim  x As  Integer
Console.WriteLine(x.GetType ())          ' Prints System.Int32  Console.WriteLine(GetType (Integer))  ' Prints System.Int32
Console.WriteLine(TypeName (x))        '
Prints Integer
Dim c as New Circle
If TypeOf  c Is  Shape Then _      Console.WriteLine("c is a Shape")
戴戒指的说法Type Conversion / Casting
Dim d As Single = 3.5
Dim i As Integer = CType (d, Integer)  ' t to 4 (Banker's rounding)
i = CInt (d)  ' same result as CType
i = Int (d)    ' t to 3 (Int function truncates the decimal)
Dim o As Object = 2
i = DirectCast (o, Integer)  ' Throws
InvalidCastException if type cast fails
Dim s As New Shape
Dim c As Circle = TryCast (s, Circle)  ' Returns Nothing if type cast fails  uint uiTotal = 123;  ulong ulTotal = 123;
鲁班怎么玩厉害
Implicitly Typed Local Variables
var s = "Hello!";
var nums = new int[] { 1, 2, 3 };  var hero = new SuperHero() { Name =
"Batman" };
Type Information
int x;
Console.WriteLine(x.GetType ());
// Prints
System.Int32
Console.WriteLine(typeof (int));              // Prints
System.Int32
Console.WriteLine(x.GetType().Name );  // prints Int32
Circle c = new Circle();  if (c is  Shape)
Console.WriteLine("c is a Shape");
Type Conversion / Casting
float d = 3.5f;
i = Convert.ToInt32(d);    // Set
to 4 (rounds)
int i = (int)d;    // t to 3
(truncates decimal)
object o = 2;
int i = (int)o;  // Throws
InvalidCastException if type cast fails
Shape s = new Shape();
Circle c = s as  Circle;  // Returns
null if type cast fails
V B.N E T
C o n s t a n t s
C #
Const  MAX_STUDENTS As  Integer = 25 ' Can t to a const or var; may be initialized in a constructor
ReadOnly  MIN_DIAMETER As  Single = 4.93
const  int MAX_STUDENTS = 25;
// Can t to a const or var; may be initialized in a constructor
readonly  float MIN_DIAMETER = 4.93f;
V B.N E T
E n u m e r a t i o n s
C #
Enum  Action    Start
[Stop]  ' Stop is a rerved word    Rewind    Forward  End Enum
Enum  Status    Flunk = 50    Pass = 70    Excel = 90  End Enum
Dim a As Action = Action.Stop  If a <> Action.Start Then _
Console.WriteLine(a.ToString & " is " & a)    ' Prints "Stop is 1"
Console.WriteLine(Status.Pass)    ' Prints
70
Console.WriteLine(Status.Pass.ToString())
enum  Action {Start, Stop, Rewind, Forward};
enum  Status {Flunk = 50, Pass = 70, Excel = 90};
Action a = Action.Stop;  if (a != Action.Start)
Console.WriteLine(a + " is " + (int) a);    // Prints "Stop is 1"
Console.WriteLine((int)
Status.Pass);    // Prints 70  Console.WriteLine(Status.Pass);      // Prints Pass
' Prints Pass
V B.N E T O p e r a t o r s C#
Comparison
=  <  >  <=  >=  <>
Arithmetic
+  -  *  /
Mod
\ (integer division)
^ (rai to a power)
娜塔丽波特曼
Assignment
=  +=  -=  *=  /=  \=  ^=  <<=  >>=  &=
Bitwi
And  Or  Xor  Not  <<  >>
Logical
AndAlso  OrEl  And  Or  Xor  Not
Note:AndAlso and OrEl perform short-circuit logical evaluations
如何推荐一本书
String Concatenation
& Comparison
模组词==  <  >  <=  >=  !=
Arithmetic
+  -  *  /
% (mod)
/ (integer division if both operands are ints)
Math.Pow(x, y)
Assignment
=  +=  -=  *=  /=  %=  &=  |= ^=  <<=  >>=  ++  --
Bitwi
&  |  ^  ~  <<  >>
Logical
&&  ||  &  |  ^  !
Note:&& and || perform short-circuit logical evaluations
String Concatenation
+
V B.N E T C h o i c e s C#

本文发布于:2023-05-16 04:19:56,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/649493.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:收藏   时候   篇文章   看到   地址   怪兽
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图