如何看待 Unity 與 Xamarin 均僅支持 C# 而不支持 VB.NET?
想當年有多少人從Pascal跳C就是因為begin和end太長而且沒有出現在鍵盤上。
個人覺得,是因為Mono目前對C#已經有了比較好的支持。而Unity只是大量用到了Mono。
當年的我也是一直抱著vb不放的,甚至感覺c#神複雜,直到後來學了學c#,vb是神馬?vb的while怎麼結尾來著,vb的for語句怎麼這麼複雜,我能用c#給你寫不
using System;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
public class GetSocket
{
private static Socket ConnectSocket(string server, int port)
{
Socket s = null;
IPHostEntry hostEntry = null;
// Get host related information.
hostEntry = Dns.GetHostEntry(server);
// Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
// an exception that occurs when the host IP Address is not compatible with the address family
// (typical in the IPv6 case).
foreach(IPAddress address in hostEntry.AddressList)
{
IPEndPoint ipe = new IPEndPoint(address, port);
Socket tempSocket =
new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
tempSocket.Connect(ipe);
if(tempSocket.Connected)
{
s = tempSocket;
break;
}
else
{
continue;
}
}
return s;
}
// This method requests the home page content for the specified server.
private static string SocketSendReceive(string server, int port)
{
string request = "GET / HTTP/1.1
Host: " + server +
"
Connection: Close
";
Byte[] bytesSent = Encoding.ASCII.GetBytes(request);
Byte[] bytesReceived = new Byte[256];
// Create a socket connection with the specified server and port.
Socket s = ConnectSocket(server, port);
if (s == null)
return ("Connection failed");
// Send request to the server.
s.Send(bytesSent, bytesSent.Length, 0);
// Receive the server home page content.
int bytes = 0;
string page = "Default HTML page on " + server + ":
";
// The following will block until te page is transmitted.
do {
bytes = s.Receive(bytesReceived, bytesReceived.Length, 0);
page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes);
}
while (bytes &> 0);
return page;
}
public static void Main(string[] args)
{
string host;
int port = 80;
if (args.Length == 0)
// If no server name is passed as argument to this program,
// use the current host name as the default.
host = Dns.GetHostName();
else
host = args[0];
string result = SocketSendReceive(host, port);
Console.WriteLine(result);
}
}
Imports System
Imports System.Text
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports Microsoft.VisualBasic
Public Class GetSocket
Private Shared Function ConnectSocket(server As String, port As Integer) As Socket
Dim s As Socket = Nothing
Dim hostEntry As IPHostEntry = Nothing
" Get host related information.
hostEntry = Dns.GetHostEntry(server)
" Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
" an exception that occurs when the host host IP Address is not compatible with the address family
" (typical in the IPv6 case).
Dim address As IPAddress
For Each address In hostEntry.AddressList
Dim endPoint As New IPEndPoint(address, port)
Dim tempSocket As New Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
tempSocket.Connect(endPoint)
If tempSocket.Connected Then
s = tempSocket
Exit For
End If
Next address
Return s
End Function
" This method requests the home page content for the specified server.
Private Shared Function SocketSendReceive(server As String, port As Integer) As String
"Set up variables and String to write to the server.
Dim ascii As Encoding = Encoding.ASCII
Dim request As String = "GET / HTTP/1.1" + ControlChars.Cr + ControlChars.Lf + "Host: " + server + ControlChars.Cr + ControlChars.Lf + "Connection: Close" + ControlChars.Cr + ControlChars.Lf + ControlChars.Cr + ControlChars.Lf
Dim bytesSent As [Byte]() = ascii.GetBytes(request)
Dim bytesReceived(255) As [Byte]
" Create a socket connection with the specified server and port.
Dim s As Socket = ConnectSocket(server, port)
If s Is Nothing Then
Return "Connection failed"
End If
" Send request to the server.
s.Send(bytesSent, bytesSent.Length, 0)
" Receive the server home page content.
Dim bytes As Int32
" Read the first 256 bytes.
Dim page as [String] = "Default HTML page on " + server + ":" + ControlChars.Cr + ControlChars.Lf
" The following will block until the page is transmitted.
Do
bytes = s.Receive(bytesReceived, bytesReceived.Length, 0)
page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes)
Loop While bytes &> 0
Return page
End Function
"Entry point which delegates to C-style main Private Function
Public Overloads Shared Sub Main()
Main(System.Environment.GetCommandLineArgs())
End Sub
Overloads Private Shared Sub Main(args() As String)
Dim host As String
Dim port As Integer = 80
If args.Length = 1 Then
" If no server name is passed as argument to this program,
" use the current host name as default.
host = Dns.GetHostName()
Else
host = args(1)
End If
Dim result As String = SocketSendReceive(host, port)
Console.WriteLine(result)
End Sub "Main
End Class
作為一個碼農你喜歡寫哪種風格的代碼?
上面時C井下面是vb
通過只支持IL體系中的一門語言而不是基於IL實現,從而拆分這個看似鐵板一塊的陣營。
推薦閱讀:
※有哪些原因會導致HRESULT:0x800704A6提示已經計劃系統關機,除了更新系統或瀏覽器?
※entity framework中怎麼通過lambda表達式生成sql語句的?
※UWP應用為什麼比桌面應用要佔用相對較多的資源?
※負責前後端開發,為什麼要學 C 語言?