4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pythonist にわかりやすい C#メモ(基本的なものしかないよ)

Last updated at Posted at 2013-10-14

variable

# int
num = 10
# str
name = 'nobjas'
# float
rate = 10.5
# bool
is_people = True
int num = 10;
string name = "nobjas";
float rate = 10.4f;
double rate2 = 10.5d;
bool isPeople = true;

list

int_list = list(1,2,3,4,5)
int_list.append(6)
List<int> intList = new List<int>() {1,2,3,4,5};
intList.Add(6);

value in list

# return True
if 2 in int_list:
    return True
else:
    return False
// return true
if (intList.Contains(2)) {
    return true;
} else {
    return false;
}

map

filterd_list = [x + 1 for x in intList]
using System.Linq;
intList = intList.Select(x => x+1);

でもまだLinqは制限がある場合があるので、下記のように書いた方が安全かも

List<int> filteredList = new List<int>();
foreach (var val in intList) {
    filteredList.Add(val + 1);
}

dict

str_int = dict(
    hoge = 10,
    huga = 20,
    )
str_int['moge'] = 30;
str_int['hoge'] += 10;
Dictionary<string, int> strInt = new Dictionary<string, int>() {
    {"hoge",10}, 
    {"huga", 20},
};
strInt.Add("moge", 30);
strInt["hoge"] += 10;

if

name = "nobjas"
if name == "noble jasper":
    print "full name"
elif name == "nobjas":
    print "short name"
else:
    print "unknown"
using System;
string name = "nobjas";
if (name == "noble jasper") {
    Console.WriteLine("full name");
} else if (name == "nobjas") {
    Console.WriteLine("short name");
} else {
    Console.WriteLine("unknown");
}

loop

sample_list = range(10);
for n in sample_list:
    print n
using System;
using System.Linq;
IEnumerable<int> sampleList = Enumerable.Range(0, 10);
foreach (int n in sampleList) {
    Console.WriteLine(n);
}
4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?