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/
C# and Game(1)Visual Studio and C#arrays
猜你喜欢
转载自sillycat.iteye.com/blog/2373971
今日推荐
周排行