C#'taki Veri Türleri: Double, Tam Sayı, Kayan Nokta, Karakter

⚡ Akıllı Özet

Data types in C# define the kind of values a variable can hold, ranging from integers and floating-point numbers to Boolean and string values, and they determine how much memory each variable reserves during program execution.

  • 🔢 Integer types: The Int32 keyword (int) stores whole numbers such as 10, 20, or 30 within a fixed memory range.
  • 🔣 Floating-point types: double and float hold decimal values, while decimal offers higher precision for financial calculations.
  • ☑️ Boolean type: The Boolean keyword stores only true or false and drives conditional logic.
  • 🔤 Metin türleri: char holds a single character, and string stores a sequence of characters as text.
  • 🧩 Value vs reference: Value types store data directly, while reference types such as string store a memory address.
  • 🤖 Yapay zeka yardımı: GitHub Copilot and ML.NET bring code suggestions and machine learning to C# type handling.

C#'ta Veri Türleri

C#'ta Veri Türleri Nelerdir?

C# dili bir dizi Temel veri türüyle birlikte gelir. Bu veri türleri, bir uygulama içinde kullanılan değerleri oluşturmak için kullanılır. C#'ta mevcut olan temel veri türlerini inceleyelim. Her örnek için Program.cs dosyamızdaki yalnızca ana işlevi değiştireceğiz.

1) Tamsayı

Sayılarla çalışmak için Tamsayı veri türleri kullanılır. Bu durumda sayılar 10, 20 veya 30 gibi tam sayılardır. C#'ta veri türü şu şekilde gösterilir: Int32 anahtar kelimesi. Aşağıda bu veri tipinin nasıl kullanılabileceğine dair bir örnek verilmiştir. Örneğimizde num adında bir Int32 değişkeni tanımlayacağız. Daha sonra değişkene bir Tamsayı değeri atayacağız ve onu buna göre görüntüleyeceğiz.

C#'ta Tamsayı Veri Türleri

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
 class Program
 { 
  static void Main(string[] args) 
  {
   Int32 num=30;
   Console.Write(num);  
   
   Console.ReadKey();
  }
 }
}

Code Açıklama:-

  1. Int32 veri türü, num adı verilen bir Tamsayı değişkenini bildirmek için belirtilir. Daha sonra değişkene 30 değeri atanır.
  2. Son olarak, sayıyı konsolda görüntülemek için console.write işlevi kullanılır.

Yukarıdaki kod doğru bir şekilde girilir ve program başarılı bir şekilde çalıştırılırsa aşağıdaki çıktı gösterilecektir.

Çıktı:

C#'ta Tamsayı Veri Türleri

Çıktıdan, num adı verilen Tamsayı değişkeninin konsolda görüntülendiğini açıkça görebilirsiniz.

2) Double

Ondalık sayılarla çalışmak için double veri türü kullanılır. Bu durumda sayılar 10.11, 20.22 veya 30.33 gibi tam sayılardır. C# dilinde veri türü “ anahtar sözcüğüyle belirtilirDouble“. Aşağıda bu veri tipinin bir örneği verilmiştir.

Örneğimizde num adında bir double değişken tanımlayacağız. Daha sonra bir Double değişkene değer verin ve ardından buna göre görüntüleyin.

Double C#'ta Veri Türleri

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
 class Program
 { 
  static void Main(string[] args) 
  {
   double num=30.33;
   Console.Write(num); 
   
   Console.ReadKey();
  }
 }
}

Code Açıklama:-

  1. Çift veri türü, çift bir türü bildirmek için belirtilir değişken numarayı aradı. Daha sonra değişkene 30.33 değeri atanır.
  2. Son olarak, sayıyı konsolda görüntülemek için console.write işlevi kullanılır.

Yukarıdaki kod doğru bir şekilde girilir ve program başarılı bir şekilde çalıştırılırsa aşağıdaki çıktı gösterilecektir.

Çıktı:

Double C#'ta Veri Türleri

Çıktıdan, num adlı double değişkenin konsolda görüntülendiğini açıkça görebilirsiniz

3) Boolean

Boolean veri türü Boolean değerleriyle çalışmak için kullanılır. doğru ve yanlış. C#'ta veri türü Boolean anahtar sözcüğüyle gösterilir. Aşağıda bu veri tipinin kullanılabileceği bir örnek verilmiştir.

Örneğimizde 'durum' adında bir Boolean değişkeni tanımlayacağız. Daha sonra değişkene bir boole değeri atayacağız ve onu buna göre görüntüleyeceğiz.

C#'ta Boolean Veri Türleri

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
 class Program
  { 
   static void Main(string[] args) 
   {
    Boolean status=true;
    Console.Write(status);
    
    Console.ReadKey();
   }
  }
}

Code Açıklama:-

  1. Boolean veri türü, 'durum' adı verilen bir Boolean değişkeni bildirmek için belirtilir. Daha sonra değişkene doğru/yanlış değeri atanır.
  2. Son olarak, Boolean değerini konsolda görüntülemek için console.write işlevi kullanılır.

Yukarıdaki kod doğru girilirse ve program başarıyla yürütülürse çıktı görüntülenecektir.

Çıktı:

C#'ta Boolean Veri Türleri

Çıktıdan, true'ya eşit olan Boolean değişkeninin konsolda görüntülendiğini açıkça görebilirsiniz.

4) Dize

String değerleriyle çalışmak için String veri türü kullanılır. C#'ta veri türü 'String' anahtar sözcüğüyle gösterilir. Aşağıda bu veri tipinin bir örneği verilmiştir.

Örneğimizde 'mesaj' adında bir String değişkeni tanımlayacağız. Daha sonra değişkene bir String değeri atayacağız ve onu buna göre görüntüleyeceğiz.

C#'ta Dize Veri Türleri

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
 class program
 {
  static void Main(string[] args)
  {
   String message="Hello";
   Console.Write(message);
   
   Console.ReadKey();
  }
 }
}

Code Açıklama:-

  1. String veri türü, mesaj adı verilen bir dize değişkenini bildirmek için belirtilir. Daha sonra değişkene “Merhaba” değeri atanır.
  2. Son olarak, string değerini konsolda görüntülemek için console.write işlevi kullanılır.

Yukarıdaki kod doğru girilirse ve program başarıyla yürütülürse çıktı görüntülenecektir.

Çıktı:

C#'ta Dize Veri Türleri

Çıktıdan, mesaj adı verilen String değişkeninin konsolda görüntülendiğini açıkça görebilirsiniz.

Complete List of C# Data Types

The four examples above cover the most common types, but C# provides a full set of built-in value data types. Each type reserves a fixed amount of memory and accepts a specific range of values, so choosing the smallest type that safely fits your data keeps a program efficient.

Veri tipi Beden Menzil / Descriptiyon
bayt 1 bayt 0 için 255
kısa 2 bayt 32,768 kadar 32,767
int (Int32) 4 bayt 2,147,483,648 kadar 2,147,483,647
ve kazandırdı 8 bayt Very large whole numbers (±9.2 quintillion)
şamandıra 4 bayt Decimals with roughly 6–7 digit precision
çift 8 bayt Decimals with roughly 15–16 digit precision
ondalık 16 bayt High-precision decimals (28–29 digits) for money
tank 2 bayt A single Unicode character
bool 1 bayt doğru ya da yanlış

Alongside these value types, the string type is the most widely used reference type and stores a sequence of characters of any length. Selecting an appropriate type prevents overflow errors and unnecessary memory use.

Value Types vs Reference Types in C#

Every C# data type falls into one of two groups: value types and reference types. This distinction controls how C# stores the data and how a variable behaves when you copy it or pass it to a method.

  • Value types: These store the actual data directly, usually on the stack. int, double, bool, char, enum, and struct are value types. Assigning one variable to another copies the value, so the two variables remain independent.
  • Reference types: These store a reference (a memory address) that points to data on the heap. string, object, arrays, and class instances are reference types. Copying a reference variable copies only the address, so both variables share the same object.

A value type variable can never be null because it always holds a value, whereas an uninitialized reference type defaults to null. Understanding this difference helps you predict how changes to data flow through a program.

Type Conversion in C#

C# frequently needs to move a value from one data type to another, such as turning user input, which is always text, into a number. This process is called type conversion, and it happens in three main ways.

  • Implicit conversion: The compiler converts automatically when there is no risk of data loss, such as assigning an int to a double. No special syntax is required.
  • Explicit conversion (casting): You place the target type in parentheses, for example (int)myDouble. Casting can lose data — converting a double to an int drops the decimal part — so you accept the risk deliberately.
  • Helper methods: The Convert class (Convert.ToInt32) and each type’s Parse method (int.Parse) turn strings into numbers, while ToString turns values back into readable text.

Choosing the correct conversion keeps data accurate and prevents runtime errors when the types on each side of an assignment do not match.

SSS

float, double, and decimal all store decimal numbers but differ in precision and size. float uses 4 bytes with about 7 digits, double uses 8 bytes with about 15 digits, and decimal uses 16 bytes for high-precision financial values.

There is no real difference. int is a C# alias for the .NET System.Int32 type, so int and Int32 compile to exactly the same thing. Most developers write int for brevity, while Int32 makes the underlying framework type explicit.

string is a reference type, because it stores a reference to character data held on the heap. However, it behaves like a value type in one way: strings are immutable, so every change creates a new string object rather than editing the old one.

A nullable type lets a value type such as int or bool also hold null, written with a trailing question mark, for example int?. It is useful for optional data and database fields, where a missing value must be represented distinctly from zero or false.

A char holds exactly one Unicode character and uses single quotes, such as ‘A’. A string holds a sequence of zero or more characters and uses double quotes. A char is a value type, while a string is a reference type.

var infers a variable’s type at compile time, and that type is then fixed with full IntelliSense support. dynamic defers type checking to runtime, so type errors surface only during execution. Use var for safety and dynamic for flexible, late-bound scenarios.

Yes. GitHub Copilot suggests type declarations, conversions, and boilerplate inside Visual Studio and Visual Studio Code. It can recommend a suitable numeric type or generate parsing code, but you should review its output, since suggestions can miss precision or overflow issues.

Yes. ML.NET maps C# data types to model features, using numeric types such as float and double for training data and string for text. Strongly typed data classes describe each column, so machine learning models integrate naturally into C# applications.

Bu yazıyı şu şekilde özetleyin: