[내일 배움 캠프 Unity 4기] 04.22 TIL

김용준·2024년 4월 22일
0

내일배움캠프

목록 보기
1/47

Goals on today

  • Make a plan for this week.
  • Study basic grammar of C#

Plans for this week

The primary goals of this week is to improve our skills via Visual Studio. Until we participate the learning camp, we already learned and practiced the C# language with the Visual Studio. And also we have experienced mini team project on last week. Now, we understood our status more accurately, we have to be familiar with the C#. Beginning from the basic grammar could be a good chance to find our weakness. After the discussion, we organized our own goals like below list.

  1. Enhance our knowledge and skills of C#
  2. Complete the personal project
  3. (As a team leader) Encourage the member
  4. (For a successful documentation) Write TIL well

C# study with lecture

The main topics learned on today are the basis of C# program; variable, data-structure and operator. Similar with the other programming language (such as C/C++, Python, ...), we have begun from the printing Hello, World!. In order to use the console, our study is started from the below script.

using namespace System;

namespace ConsoleApp1
{
	internal class Program
    {
    	static void Main(string[] args)
        {
        	Console.WriteLine("Hello, World!");
        }
    }
}

In this time, we do not focus on the frame of this script; namespace, class, static,... . The Console.WriteLine() method can be separate with its structure. Since we planned to use 'Console', this script calls the Console. And we wrote the function to print out the string; WriteLine(). Connecting those, we can see the Hello, World! on the window of console.

Type (variable)

Before the calculating(computing), we should define the data type of what we transferred to computer. The C# language is not pretty different with trandition of other languages.

	int x = 0; // Integer type
    float y = 1.0f ; // Real number up to (-45, 38)
    bool z = true; // Boolean type

Those example contains the initialization while the declaration. To shrink the total line of script and to avoid the calculation of thresh value, the declaration with initialization is recommanded.

var

The type of variable could be automatically decided according the type of initialization. However, the user(writer) should be recognized the type of var via below operator/method

// method
int a=0;
Console.WriteLine(a.GetType().Name());

string str_a = "";
Console.WriteLine(str_a.GetType().Name());

// operator
Console.WriteLine(typeof(int).Name());
Console.WriteLine(typeof(string).Name());

Identifier

The names of variable are also regarded as an important component to read the script. To distinguish the variable to the method, the identifier begins with the small character such as int score = 0;,float wavLen = 320.0;.

Q & A

Q1. I have learned that the logic result of 0.1+0.2==0.3 is false. However, the C# script with below gives true. What is the difference?

float fa = 0.1f;
float fb = 0.2f;
bool ba = fa+fb==0.3f;
Console.WriteLine(ba);

A1. Generally, the calculation of 0.1 +0.2 does not exactly same with 0.3 because the calculation has done with the approximation. However, the Visual Studio contains the internal compensating process. So the below script also gives true as a result

float fa = 0.1f;
float fb = 0.09999999f
Console.WriteLine(fa==fb);

Q2. Then, is it often to facilitate the precision of double when developing game?
A2. Not frequently, we would use approximation for that kind of situation

profile
꿈이큰개발자지망생

1개의 댓글

comment-user-thumbnail
2024년 6월 2일

글이 쉽네요 ^^ 잘 읽고 갑니다 ^^. 이번 프로젝트도 파이팅이예요!!

답글 달기