Skip to content

Instantly share code, notes, and snippets.

@musaprg
Last active March 17, 2017 09:05
Show Gist options
  • Save musaprg/b693044de8b1a2b6117da2e252885a38 to your computer and use it in GitHub Desktop.
Save musaprg/b693044de8b1a2b6117da2e252885a38 to your computer and use it in GitHub Desktop.
C#入門で書いたコード
using System;
namespace CSharpLearning
{
class MainClass
{
struct Point
{
public int x;
public int y;
}
public static void Main(string[] args)
{
int x = 3;
int y = 4;
Console.WriteLine(x + y);
Console.WriteLine(x - y);
Console.WriteLine(x * y);
Console.WriteLine(x / y);
Console.WriteLine("---");
double f = 5.5;
int f_dash = (int)f;
Console.WriteLine(f);
Console.WriteLine(f_dash);
Console.WriteLine("---");
string s = "サンプルテキスト";
Console.WriteLine(s + "追加のテキスト");
Console.WriteLine("{0}と{1}はお友達", 10, 20);
Console.WriteLine(string.Format("{0}と{1}はお友達", 10, 20));
Console.WriteLine("---");
int[] arrx = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int i = 0;
while (i < arrx.Length)
{
Console.WriteLine(arrx[i]);
++i;
}
Console.WriteLine("---");
for (i = 0; i < arrx.Length; i++)
{
Console.WriteLine(arrx[i]);
}
Console.WriteLine("---");
foreach (var item in arrx)
{
Console.WriteLine(item);
}
Console.WriteLine("---");
foreach (var item in arrx)
{
if (item % 2 == 0)
{
Console.WriteLine("偶数");
}
else
{
Console.WriteLine("奇数");
}
}
Console.WriteLine("---");
x = 2;
int sq = Square(x);
Console.WriteLine(sq);
Console.WriteLine("---");
var p = new Point { x = 10, y = 10 };
Console.WriteLine("p.x is {0}", p.x);
Console.WriteLine("p.y is {0}", p.y);
}
static int Square(int x)
{
return x * x;
}
}
}
using System;
namespace CSharpLearning
{
class MainClass
{
public static void Main(string[] args)
{
int max = 100;
for (int i = 1; i < max; i++)
{
if (i % 15 == 0)
{
Console.WriteLine("Fizz Buzz");
}
else if (i % 3 == 0)
{
Console.WriteLine("Fizz");
}
else if(i % 5 == 0)
{
Console.WriteLine("Buzz");
}
else
{
Console.WriteLine(i);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment