If you are familiar with C#, you might have seen arrays created with the new keyword, and perhaps you have seen arrays with a specified size as well. In C#, there are different ways to create an array:

// Create an array of four elements, and add values later
string[] cars = new string[4];

// Create an array of four elements and add values right away 
string[] cars = new string[4] {"Volvo", "BMW", "Ford", "Mazda"};

// Create an array of four elements without specifying the size 
string[] cars = new string[] {"Volvo", "BMW", "Ford", "Mazda"};

// Create an array of four elements, omitting the new keyword, and without specifying the size
string[] cars = {"Volvo", "BMW", "Ford", "Mazda"};

 

It is up to you which option you choose. In our tutorial, we will often use the last option, as it is faster and easier to read.
However, you should note that if you declare an array and initialize it later, you have to use the new keyword:

// Declare an array
string[] cars;

// Add values, using new
cars = new string[] {"Volvo", "BMW", "Ford"};

// Add values without using new (this will cause an error)
cars = {"Volvo", "BMW", "Ford"};	// 불가능!

즉, 배열 변수를 선언하면서 바로 값을 대입할 때를 제외하고 'new'는 생략 할 수 없다.

배열의 공간 크기는 선은을 해도 되고, 생략해도 된다.

왠만하면 그냥 'new'는 항상 쓰는 습관을 갖자...

 

 

Reference : C# Arrays (w3schools.com)

 

C# Arrays

C# Arrays Create an Array Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value. To declare an array, define the variable type with square brackets: We have now declared a variable that holds

www.w3schools.com

 

1. 고전 방식

for (int i = 0; i < 5; i++) 
{
  Console.WriteLine(i);
}

 

2. foreach

문법

foreach (type variableName in arrayName) 
{
  // code block to be executed
}

 

예제

string[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
foreach (string i in cars) 
{
  Console.WriteLine(i);
}

 

문법

variable = (condition) ? expressionTrue :  expressionFalse;

 

예제

int time = 20;
string result = (time < 18) ? "Good day." : "Good evening.";
Console.WriteLine(result);

결과 : 
Good evening.

& : 2진수 and 연산
| : 2진수 or 연산
>> : 2진수 right shift 연산
<< : 2진수 left shift 연산

 

== : 논리 equal 연산
!= : 논리 not equal 연산

 

&& : 논리 and 연산
|| : 논리 or 연산
! : 논리 not 연산

 

using System;

namespace MyApplication
{
  class Program
  {
    static void Main(string[] args)
    {
      string firstName = "John";
      string lastName = "Doe";
      string name = $"My full name is: {firstName} {lastName}";
      Console.WriteLine(name);
    }
  }
}

결과 : 

My full name is: John Doe

 

자바스크립트와 비교

// C#
$"My full name is: {firstName} {lastName}";

// JavaScript
`My full name is: ${firstName} ${lastName}`;

1. Implicit Casting (automatically)

: converting a smaller type to a larger type size

char -> int -> long -> float -> double

int myInt = 9;
double myDouble = myInt;       // Automatic casting: int to double

Console.WriteLine(myInt);      // Outputs 9
Console.WriteLine(myDouble);   // Outputs 9

작은 데이터 타입을 큰 데이터 타입에 넣기 때문에 명시적으로 형변환을 해주지 않아도 알아서 형변환 된다.

 

2. Explicit Casting (manually)

: converting a larger type to a smaller size type

double -> float -> long -> int -> char

double myDouble = 9.78;
int myInt = (int) myDouble;    // Manual casting: double to int

Console.WriteLine(myDouble);   // Outputs 9.78
Console.WriteLine(myInt);      // Outputs 9

큰 데이터 타입을 작은 데이터 타입에 넣기 위해 명시적 형변환.

 

3. Type Conversion Methods (함수, Function)

It is also possible to convert data types explicitly by using built-in methods, such as Convert.ToBoolean, Convert.ToDouble, Convert.ToString, Convert.ToInt32 (int) and Convert.ToInt64 (long):

int myInt = 10;
double myDouble = 5.25;
bool myBool = true;

Console.WriteLine(Convert.ToString(myInt));    // convert int to string
Console.WriteLine(Convert.ToDouble(myInt));    // convert int to double
Console.WriteLine(Convert.ToInt32(myDouble));  // convert double to int
Console.WriteLine(Convert.ToString(myBool));   // convert bool to string

 

 

Reference : C# Type Casting (w3schools.com)

 

C# Type Casting

C# Type Casting C# Type Casting Type casting is when you assign a value of one data type to another type. In C#, there are two types of casting: Implicit Casting (automatically) - converting a smaller type to a larger type size char -> int -> long -> float

www.w3schools.com

 

  • Open Keychain Access
  • Select Keychains -> login and Category -> Passwords
  • Type github.com in search box, you should see an entry (or entries) of Internet Passwordkind for github.com. Right click & Delete them.
  • Go back to terminal and retry the git command that requires the password
  • Type in your git username and password when prompted

+ Recent posts