public static void Main() { try { int a = 1; int b = 1; var result = Division(a, b); Console.WriteLine(result); Temprature temp = new Temprature(); temp.showTemp(); } catch (DivideByZeroException e) { Console.WriteLine(e); } catch (Exception e) { Console.WriteLine(e); } finally { Console.WriteLine("Hello Mr. Raverkar"); } }
public async Task <IActionResult> PutTemprature(int id, Temprature temprature) { if (id != temprature.Id) { return(BadRequest()); } _context.Entry(temprature).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TempratureExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
// This temp == 5 // obj == 6 // return -1 /// <summary></summary> /// <param name="obj"></param> /// <returns> /// Less than zero - The current instance precedes the object specified by the CompareTo method in the sort order. /// Zero - This current instance occurs in the same position in the sort order as the object specified in the CompareTo method. /// Greater than zero - This current instance follows the object specified by the CompareTo method in the sort order. /// </returns> public int CompareTo(object obj) { // This should be after the passed object - 'hotter' than the passed object. if (obj == null) { return(1); } // Cast obj to temperature. Temprature otherTemp = obj as Temprature; if (otherTemp != null) { // Now we can compare them. if (this.temperature < otherTemp.temperature) { return(-1); } else if (this.temperature == otherTemp.temperature) { return(0); } else { return(1); } } else { throw new ArgumentException("Object is not a temperature."); } }
public async Task <ActionResult <Temprature> > PostTemprature(Temprature temprature) { temprature.Date = DateTime.Now; _context.Temprature.Add(temprature); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTemprature", new { id = temprature.Id }, temprature)); }
static void Main(string[] args) { Temprature temp = new Temprature(); float todayTemp = temp[1]; // read temp[1] = -5.0F; // Write Console.WriteLine(todayTemp); Console.ReadKey(); }
public static TempratureConversionResponse GetResponse(Temprature temprature, string message) { return(new TempratureConversionResponse { Temprature = new TempratureResponseModel() { ConvertedTemprature = temprature.ConvertedTemprature, ConvertedUnit = temprature.ConvertedUnit.ToString(), CurrentTemprature = temprature.CurrentTemprature, CurrentUnit = temprature.CurrentUnit.ToString() }, Message = message }); }
static void Main(string[] args) { //Uppgift 1 Invånare i = new Invånare(); Console.WriteLine("Ange s**tår"); try { var s**tår = int.Parse(Console.ReadLine()); Console.WriteLine("Antalet invånare mellan 2015 och " + s**tår + " är " + i.AntalInvånare(s**tår)); } catch { throw new FormatException("Felaktigt inmating"); } Console.ReadKey(); // Uppgift 2 Temprature temp = new Temprature(); Console.Write("Ange en temperatur "); try { var angiventemp = int.Parse(Console.ReadLine()); temp.CheckTemp(angiventemp); } catch { throw new FormatException("Felaktigt inmating"); } Console.ReadKey(); //Uppgift 7 Grönalund g = new Grönalund(); Console.WriteLine("Ange Ålder"); try { g.ålder(int.Parse(Console.ReadLine())); Console.WriteLine("Vill du fortsätta? Ja för att forsätta Nej för att gå vidare till betalning."); g.val(Console.ReadLine().ToLower()); } catch { throw new Exception("Något gick fel, har du fyllt i informationen rätt"); } Console.ReadKey(); }
public void SendPackageToTcp() { TempraturePackage package = new TempraturePackage(); package["Stx"] = (byte)1; package["Lenght"] = (byte)2; package["Type"] = (byte)3; package["Temprature"] = new Temprature() { Degree = 4 }; package["Checksum"] = (ushort)47694; package["Etx"] = (byte)6; _tcpListener.SendFromApi(package, new TcpDestInfo() { IpAddress = "192.168.1.34", Port = 1256 }); }
public void SendPackageToUdp() { TempraturePackage package = new TempraturePackage(); package["Stx"] = (byte)1; package["Lenght"] = (byte)2; package["Type"] = (byte)3; package["Temprature"] = new Temprature() { Degree = 4 }; package["Checksum"] = (ushort)47694; package["Etx"] = (byte)6; string json = JsonConvert.SerializeObject(package); TempraturePackage package2 = JsonConvert.DeserializeObject <TempraturePackage>(json); _udpListener.SendFromApi(package2, new UdpDestInfo() { IpAddress = "192.168.1.34", Port = 1256 }); }