You can download .NET 6 Preview 3, for Windows, macOS, and Linux.
اشتراکها
اشتراکها
روش های مدرن برای ثبت خطا در سی شارپ
Logging is a big part of software development for many years now. One can argue that a logging mechanism is a must-have part of any application or library. I would agree with that statement. Logging has a crucial part to play in a scenario where you can’t use interactive debugging (that is, attaching a debugger like Visual Studio). It allows us to investigate errors after the problem already happened. In some cases, like Production Debugging, logs might be the only information you have.
Rust، زبان برنامه نویسی سیستمی است که برای ایمنی، همزمانی و عملکرد طراحی شدهاست و همین جهت به یک انتخاب محبوب برای توسعهی نرم افزارهای مدرن تبدیل شدهاست. struct یکی از بلوکهای ساختمانی اساسی در Rust ساختار است که مخفف کلمهی 'structure' است. ساختارها، انواع دادههای سفارشی هستند که به توسعه دهندگان اجازه میدهند تا دادههای مرتبط را به شیوهای تمیز و کارآمد، با هم گروه بندی کنند. در این مقاله، قدرت و انعطافپذیری سازهها را در Rust، بررسی میکنیم و یاد میگیریم که چگونه، بهطور مؤثری از آنها در پروژههای Rust خود استفاده کنیم.
برای ایجاد یک نمونه از یک ساختار تاپل، از نام و مقادیر، داخل پرانتز استفاده کنید:
تعریف struct
برای تعریف struct در Rust، از کلمهی کلیدی struct استفاده کنید و به دنبال آن، نام ساختار و فیلدهای آن در براکتهایی باز و بسته محصور میشود. هر فیلد باید یک نام و یک نوع داشته باشد که با : از هم جدا شدهاند. به عنوان مثال در اینجا یک ساختار ساده، نشان دهندهی یک نقطهی دو بعدی است:
struct Point { x: f64, y: f64, }
نمونه مقدار دهی struct :
let point = Point { x: 1.0, y: 2.0 };
دسترسی به فیلدهای struct :
برای دسترسی به فیلدهای یک struct ، از علامت نقطه استفاده کنید:
let x = point.x; let y = point.y;
نمونه های struct قابل تغییر
برای ایجاد یک نمونهی قابل تغییر از یک struct ، از کلمهی کلیدی mut استفاده کنید که به شما امکان میدهد تا مقادیر فیلدها را تغییر دهید:
let mut point = Point { x: 1.0, y: 2.0 }; point.x = 3.0; point.y = 4.0;
Tuple Struct
Rust همچنین از ساختارهای tuple نیز پشتیبانی میکند که ساختارهایی بدون نام فیلدها هستند. آنها زمانی مفید هستند که میخواهید یک ساختار را با تعداد کمی فیلد ایجاد کنید و نیازی به نامگذاری صریح آنها ندارید. برای تعریف ساختار tuple، از کلمهی کلیدی struct و به دنبال آن، نام و انواع فیلدهای داخل پرانتز استفاده کنید:
struct Color(u8, u8, u8);
let red = Color(255, 0, 0);
Unit Struct
unit struct یک struct بدون هیچ فیلدی است. برای تعریف ساختار واحد، از کلمهی کلیدی struct و به دنبال آن نام و نقطه ویرگول استفاده کنید:
struct Jump; struct Crouch; struct Attack; struct Character { name: String, } fn perform_action(character: &Character, action: &dyn Any) { if action.is::<Jump>() { println!("{} jumps!", character.name); } else if action.is::<Crouch>() { println!("{} crouches!", character.name); } else if action.is::<Attack>() { println!("{} attacks!", character.name); } else { println!("{} does nothing...", character.name); } } fn main() { let character = Character { name: "John Doe".to_string(), }; perform_action(&character, &Jump); perform_action(&character, &Crouch); perform_action(&character, &Attack); }
Structs in Rust روشی قدرتمند و انعطافپذیر را برای تعریف انواع دادههای سفارشی که دادههای مرتبط را با هم گروهبندی میکنند، ارائه میکند. آنها با کپسوله کردن دادهها و عملکردهای مرتبط، به ایجاد کد تمیز و قابل نگهداری کمک میکنند. در این مقاله، ما اصول اولیه تعریف، نمونه سازی و دسترسی به ساختارها و همچنین موضوعات پیشرفتهای مانند ساختارهای tuple ، unit struct و را بررسی کردیم. با درک کاملی از ساختارها، میتوانید پتانسیل کامل Rust را در پروژههای خود آزمایش کنید و نرمافزاری کارآمد و ایمن بسازید.
اشتراکها
مقایسه Android ، IOS و Windows Phone
You don't know what you have until you lose it.
We all know what it means, but we often forget that it also applies to
our health. In no way is this article intended to lecture you or make
you feel guilty about your lifestyle. With this article, I simply want
to share a few tips that can help you stay healthy as a programmer.
ASP.NET is almost 15 years old and it has evolved to become a flexible and extremely powerful platform. But 15 years is a long time, especially in the world of web technology, and the folks at Microsoft knew it was time to change ASP.NET.
In this course, Envato Tuts+ instructor Jeremy McPeak will walk you through the major changes to ASP.NET in version 5. Along the way, you'll see how these changes will affect your project and how the new features can make your life as a developer easier. You'll also get a first look at the new Tag Helpers, inversion of control and dependency injection features, with practical examples.
اشتراکها
ImageSharp.Web 2.0.0 منتشر شد
This is another post in our Code Health series. A version of this post originally appeared in Google bathrooms worldwide as a Google Testing on the Toilet episode. You can download a printer-friendly version to display in your office