package main
import "fmt"
type Person struct {
Name string
Age int
Email string
}
func main() {
// Struct örneği oluşturma
p := Person{
Name: "Ali",
Age: 30,
Email: "[email protected]",
}
fmt.Println("Kişi Bilgileri:", p.Name, p.Age, p.Email)
}
package main
import "fmt"
type Book struct {
Title string
Author string
Pages int
}
func main() {
b := Book{
Title: "Go Programlama",
}
fmt.Println("Kitap:", b.Title, b.Author, b.Pages)
}
package main
import "fmt"
type Rectangle struct {
Width float64
Height float64
}
// Alan hesaplama metodu
func (r Rectangle) Area() float64 {
return r.Width * r.Height
}
func main() {
rect := Rectangle{Width: 10.5, Height: 5.0}
area := rect.Area()
fmt.Println("Dikdörtgen Alanı:", area)
}
package main
import "fmt"
type Address struct {
City string
Country string
}
type Employee struct {
Name string
ID int
Address Address
}
func main() {
emp := Employee{
Name: "Ayşe",
ID: 101,
Address: Address{
City: "İstanbul",
Country: "Türkiye",
},
}
fmt.Printf("Çalışan: %s, Şehir: %s\n", emp.Name, emp.Address.City)
}
// User represents a system user
type User struct {
Username string // Kullanıcı adı
Role string // Kullanıcı rolü
}
using Microsoft.AspNetCore.Mvc;
namespace MyWebApp.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult About()
{
ViewData["Message"] = "Bu bir hakkımda sayfasıdır.";
return View();
}
}
}
public class ProductController : Controller
{
public IActionResult Detail(int id)
{
// Veritabanından ürün bilgisi çekiliyor (örnek olarak sabit veri kullanıyoruz)
var product = new { Id = id, Name = "Örnek Ürün", Price = 99.90 };
return View(product);
}
}
public class ContactController : Controller
{
[HttpGet]
public IActionResult Index()
{
return View();
}
[HttpPost]
public IActionResult Index(string name, string message)
{
if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(message))
{
ViewBag.SuccessMessage = $"{name}, mesajınız başarıyla gönderildi!";
}
return View();
}
}
[ResponseCache(Duration = 60)]
public IActionResult Index()
{
return View();
}
public IActionResult NotFound()
{
return View();
}
ViewBag.Title = "ASP[DOT]NET Kontroller Rehberi";
ViewBag.Description = "ASP[DOT]NET MVC kontrolleri ile web geliştirme nasıl yapılır öğrenin.";