قوانین و مفاهیم پایه کد نویسی در کاتلین پارت ۲

kotlin-2

قوانین و مفاهیم پایه کد نویسی در کاتلین

 

سلام خدمت دوستان و همراهان عزیز مجموعه آموزشی فرکیان تک

امیدواریم که حال شما عزیزان عالی باشه

توی این مقاله قراره با هم یه نگاهی به قواعد کد نویسی زبان کاتلین داشته باشیم. بریم که داشته باشیم…

 

 

پارت دوم

اگر پارت ۱ رو نخوندی پیشنهاد میکنم بری بخونی کافیه روی لینک کلیک کنی.

Top Level Variables

اگر خارج از بدنه متد و کلاس و داخل فایل، یک variable تعریف کنیم، Top Level Variable میگویند. یکی از خصوصیات این نوع از متغیرها این هست که همه قابل رؤیت هستن.

String Template

مثلاً یک متغیر داریم:

var b : String = “Farkiantech”

حالا میخوایم با یک متغیر دیگه ترکیب کنیم:

println(“Welcome to $ b”)

String Template

 

همونطور که مشاهده کردین، اومدیم برای اینکه محتوای یک متغیر رو با یک متن دیگه ترکیب کنیم از علامت $ استفاده کردیم.

یکی از ویژگی های که علامت $  داره اینه که به صورت خودکار نوع Int  را به String تبدیل میکند.

اگر بخوایم خروجی یک متد را به عنوان String  استفاده کنیم از علامت {} استفاده میکنیم و متد خودمون رو صدا میزنیم:

sum

 

 

تعریف Class در کاتلین:

ابتدا کلید واژه class و سپس اسم کلاس. سپس برای استفاده از اون داخل متد main یک متغیر ایجاد کرده و یک instance از

کلاسمون رو ایجاد میکنیم.

class

 

برای تعریف Constructor داخل یک کلاس، یک پرانتز ایجاد و پارامتر های لازم را ایجاد میکنیم:

constructor

برای اینکه یک متد، ویژگی، یا فیلدی در کلاس تعریف کنیم، داخل {} باید قرار بگیره. همچنین اگر بخوایم از پارامترهایی که در

Constructor تعریف کردیم، در متد ساخته شده استفاده کنیم، باید قبل از پارامتر، از val یا var  استفاده میکنیم.

constructor2

 

 

اگر بخوایم تغییری روی پارامترهای Constructor اعمال کنیم، در بدنه کلاس از بلاک {}init استفده میکنیم:

constructor3

امیدوارم که این مقاله براتون مفید باشه، در آینده مطالب بیشتری رو خدمتتون تقدیم میکنم.

ارسال دیدگاه

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *


Warning: file_put_contents(): Only -1 of 865 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 81 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 1043 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 248 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 114515 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 11015 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 25691 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 727 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 291 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 8792 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 2347 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 129 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 59046 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 355 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 1058 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 57 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 2279 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 267405 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 160218 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 11343 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 4186 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 152851 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 5663 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 20330 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 53381 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 1393 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 451276 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 513 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 5865 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 1558988 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 60262 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 26702 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 6396 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 3678 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 58071 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 983 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 975 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 614 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 442 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 237 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 12945 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 254 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Warning: file_put_contents(): Only -1 of 77 bytes written, possibly out of free disk space in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/file.cls.php on line 172

Fatal error: Uncaught ErrorException: md5_file(/home/farkia/domains/farkiantech.com/public_html/wp-content/litespeed/js/e06c4a9f820fa29264ec899a81b6db4a.js.tmp): failed to open stream: No such file or directory in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/optimizer.cls.php:140 Stack trace: #0 [internal function]: litespeed_exception_handler(2, 'md5_file(/home/...', '/home/farkia/do...', 140, Array) #1 /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/optimizer.cls.php(140): md5_file('/home/farkia/do...') #2 /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/optimize.cls.php(837): LiteSpeed\Optimizer->serve('https://farkian...', 'js', true, Array) #3 /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/optimize.cls.php(382): LiteSpeed\Optimize->_build_hash_url(Array, 'js') #4 /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/optimiz in /home/farkia/domains/farkiantech.com/public_html/wp-content/plugins/litespeed-cache/src/optimizer.cls.php on line 140