C# and Game(1)Visual Studio and C#arrays

本文介绍了如何在Mac上安装Visual Studio并使用C#创建第一个Hello World程序。此外还详细讲解了C#中数组的基本用法,包括一维数组、多维数组的操作及隐式类型数组的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C# and Game(1)Visual Studio and C#arrays


Install Visual Studio on MAC

Start the first Hello world example
using System;

namespace HelloWorld
{
class Hello
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
}

Same comments rule as JAVA.
Using System, more about the INPUT/OUTPUT of the system. https://docs.microsoft.com/en-us/dotnet/api/system.io?view=netframework-4.7

Arrays in C#
type[] arrayName, similar to JAVA, same type

//Carl's first code example
using System;
using System.Collections.Generic;
using System.Linq;

namespace HelloWorld
{
class Hello
{
public static void Main(string[] args)
{
// Specify the data source.
int[] scores = new int[] { 97, 92, 81, 60 };

// Define the query expression.
IEnumerable<int> scoreQuery =
from score in scores
where score > 80
select score;

// Execute the query.
foreach (int i in scoreQuery)
{
Console.Write(i + " ");
}
}
}
}

Single Dimensional Arrays
string[] stringArray = new string[6];

Multidimensional Arrays, I guess I will never use that.
int[,] array = new int[4, 2];
int[,] array4 = { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };
int[,] array2Da = new int[4, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };

Array operation foreach
int[] numbers = { 4, 5, 6, 1, 2, 3, -2, -1, 0 };
foreach (int i in numbers)
{
System.Console.Write(" " + i);
}

Passing Arrays Using ref and out
// Initialize the array:
int[] theArray = { 1, 2, 3, 4, 5 };
// Pass the array using ref:
FillArray(ref theArray);

int[] theArray; // Initialization is not required
// Pass the array to the callee using out:
FillArray(out theArray);

Implicitly Typed Arrays
var a = new[] { 1, 10, 100, 1000 }; // int[]
var b = new[] { "hello", null, "world" }; // string[]


References:
https://unity3d.com/
https://unity3d.com/learn/resources/downloads
https://unity3d.com/learn/tutorials/topics/scripting/installing-tools-unity-development?playlist=17117

https://msdn.microsoft.com/en-us/library/k1sx6ed2.aspx
array
https://docs.microsoft.com/en-us/dotnet/articles/csharp/programming-guide/arrays/
class and structure
https://docs.microsoft.com/en-us/dotnet/articles/csharp/programming-guide/classes-and-structs/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值