using System;
using System.IO;
using System.IO.Compression; //このLibを使う
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
string startPath = @"c:\example\start";
string zipPath = @"c:\example\result.zip";
string extractPath = @"c:\example\extract";
ZipFile.CreateFromDirectory(startPath, zipPath);
ZipFile.ExtractToDirectory(zipPath, extractPath);
}
}
}
ちなみに、「@」を利用するとエスケープを行わずに「/」を文字列に含められるので、パスを指定したい場合などに可読性が高く、便利に使える。
2018年1月26日金曜日
2018年1月24日水曜日
C# delegate
A delegate is like a pointer to a function. It is a reference type data type and it holds the reference of a method.
delegate は代表の意味である。定義と同じ戻り値と引数を持つMethodを代入できる。
class Program
{
// declare delegate
public delegate void Print(int value);
static void Main(string[] args)
{
// Print delegate points to PrintNumber
Print printDel = PrintNumber;
printDel(100000);
printDel(200);
// Print delegate points to PrintMoney
printDel = PrintMoney;
printDel(10000);
printDel(200);
}
public static void PrintNumber(int num)
{
Console.WriteLine("Number: {0,-12:N0}",num);
}
public static void PrintMoney(int money)
{
Console.WriteLine("Money: {0:C}", money);
}
}
A method can have a parameter of a delegate type and can invoke the delegate parameter.
public static void PrintHelper(Print delegateFunc, int numToPrint)
{
delegateFunc(numToPrint);
}
delegate は代表の意味である。定義と同じ戻り値と引数を持つMethodを代入できる。
class Program
{
// declare delegate
public delegate void Print(int value);
static void Main(string[] args)
{
// Print delegate points to PrintNumber
Print printDel = PrintNumber;
printDel(100000);
printDel(200);
// Print delegate points to PrintMoney
printDel = PrintMoney;
printDel(10000);
printDel(200);
}
public static void PrintNumber(int num)
{
Console.WriteLine("Number: {0,-12:N0}",num);
}
public static void PrintMoney(int money)
{
Console.WriteLine("Money: {0:C}", money);
}
}
public static void PrintHelper(Print delegateFunc, int numToPrint)
{
delegateFunc(numToPrint);
}
参考:http://www.tutorialsteacher.com/csharp/csharp-delegates
2018年1月12日金曜日
vba Variantのnullとempty
値 Empty は、初期化されていない (初期値が代入されていない) Variant 変数を示します。
Null は、 Variant 変数に意図的に有効なデータが格納されていないことを示します。
Null は、 Variant 変数に意図的に有効なデータが格納されていないことを示します。
2017年12月25日月曜日
vba動的array
VBAで配列のサイズを指定しないと、エラーとなる
Dim isholiday() As Boolean
isholiday(0) = checkHoliday(sWeek)
真ん中に、下記記述を入れるとOK
ReDim isholiday(endDate - startDate)
最初から以下のように指定してもNGだった
Dim isholiday(endDate - startDate) As Boolean
Dim isholiday() As Boolean
isholiday(0) = checkHoliday(sWeek)
真ん中に、下記記述を入れるとOK
ReDim isholiday(endDate - startDate)
最初から以下のように指定してもNGだった
Dim isholiday(endDate - startDate) As Boolean
2017年12月12日火曜日
C# Array
int[] a1 = new int[10]; //10 elements
int[,] a2 = new int[10, 5]; //二次、50 (10 × 5) elements
int[,,] a3 = new int[10, 5, 2]; //三次、100 (10 × 5 × 2) elements
// An array with elements of an array type is sometimes called a jagged array because the lengths of the element arrays do not all have to be the same.
// creates an array with three elements, each of type int[] and each with an initial value of null
int[][] a = new int[3][];
a[0] = new int[10];
a[1] = new int[5];
a[2] = new int[20];
// allocates and initializes an int[] with three elements. the length of the array is inferred from the number of expressions between { and }
int[] a = new int[] {1, 2, 3};
// Local variable and field declarations can be shortened further such that the array type does not have to be restated
int[] a = {1, 2, 3};
int[,] a2 = new int[10, 5]; //二次、50 (10 × 5) elements
int[,,] a3 = new int[10, 5, 2]; //三次、100 (10 × 5 × 2) elements
// An array with elements of an array type is sometimes called a jagged array because the lengths of the element arrays do not all have to be the same.
// creates an array with three elements, each of type int[] and each with an initial value of null
int[][] a = new int[3][];
a[0] = new int[10];
a[1] = new int[5];
a[2] = new int[20];
// allocates and initializes an int[] with three elements. the length of the array is inferred from the number of expressions between { and }
int[] a = new int[] {1, 2, 3};
// Local variable and field declarations can be shortened further such that the array type does not have to be restated
int[] a = {1, 2, 3};
2017年11月30日木曜日
DjangoのModel使用
1)Modelを定義
appフォルダーにmodels.pyにTableとColumnを定義
from django.db import models
# Create your models here.
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
2)appをProjectに結び付く
settings.pyのINSTALLED_APPSにappを追加
INSTALLED_APPS = [
'polls.apps.PollsConfig',
.....
3)migrations作成
python manage.py makemigrations polls
4)migrate実施
python manage.py sqlmigrate polls 0001 #どんなSQL実行されるか確認
python manage.py migrate
appフォルダーにmodels.pyにTableとColumnを定義
from django.db import models
# Create your models here.
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
2)appをProjectに結び付く
settings.pyのINSTALLED_APPSにappを追加
INSTALLED_APPS = [
'polls.apps.PollsConfig',
.....
3)migrations作成
python manage.py makemigrations polls
4)migrate実施
python manage.py sqlmigrate polls 0001 #どんなSQL実行されるか確認
python manage.py migrate
登録:
投稿 (Atom)