Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Exemplu OOP inventar
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Newtonsoft.Json; namespace Rextester{ public class Inventar{ //Presupunem inventar de 10x5 //Numerotat de la 1 la 50 private static int[,] items = new int[51,2]; // [posx, 0] = itmID; // [posx, 1] = itmCount; public Inventar(){ //De aici citești un fișier în care ai puse toate datele despre //iteme, cum ar fi: imagine, nume, etc, etc :)) //Poate chiar și proprietăți, depinde de ce stochezi Console.WriteLine("Obiect initializat"); } public static void setItm(int pos, int itmID, int itmCount){ items[pos,0] = itmID; items[pos,1] = itmCount; } public static void saveToFile(){ string json = JsonConvert.SerializeObject(items); //Scrii în „inventar.data” stringul json Console.WriteLine("Salvat in fisier" + json); } public static void getFromFile(){ //Iei din fișier textul //Presupunem ca apoi il salvezi in stringul json string json = "[[0,0],[5,4],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]]"; Console.WriteLine("Extras din fișier"); //Îl parsezi, apoi îl salvezi string[,] deserialized = JsonConvert.DeserializeObject<string[,]>(json); for(int i=1;i<=50;i++){ setItm(i, Int32.Parse(deserialized[i,0]), Int32.Parse(deserialized[i,1])); i++; } } } public class Program{ public static void Main(string[] args){ //Your code goes here Inventar inv = new Inventar(); Inventar.setItm(1, 1, 4); Inventar.setItm(1, 3, 4); Inventar.setItm(1, 5, 4); Inventar.getFromFile(); //Inventar.saveToFile(); //Console.WriteLine(Inventar.test(1, 2)); } } }
Show compiler warnings
[
+
]
Show input
Compilation time: 0,14 sec, absolute running time: 0,28 sec, cpu time: 0,28 sec, average memory usage: 22 Mb, average nr of threads: 5
edit mode
|
history
|
discussion
Obiect initializat Extras din fișier