- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Buffer SetByte Example in C#
The SetByte() method assigns a specified value to a byte at a particular location in a specified array.
Firstly, set an array −
int[] arr = { 3, 4, 12 };
Now, use SetByte() to assign values −
Buffer.SetByte(arr, 3, 20);
Here is the complete code −
Example
using System; using System.Text; public class Demo { public static void Main() { int[] arr = { 3, 4, 12 }; Console.WriteLine("Initial Array..."); // loop through the byte array for (int i = 0; i < Buffer.ByteLength(arr); i++) { Console.WriteLine(Buffer.GetByte(arr, i)); } Buffer.SetByte(arr, 3, 20); Console.WriteLine("New Array..."); // loop through the new byte array for (int i = 0; i < Buffer.ByteLength(arr); i++) { Console.WriteLine(Buffer.GetByte(arr, i)); } } }
Output
Initial Array... 3 0 0 0 4 0 0 0 12 0 0 0 New Array... 3 0 0 20 4 0 0 0 12 0 0 0
Advertisements