using System;
namespace ConsoleApplication285
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.MapGet("/", () => "Hello World!");
app.Run();
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddSingleton<IGameRepository, FakeGameRepository>();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.MapPost("games", async (Game game, IGameRepository repo)
=>
{
await repo.CreateAsync(game);
return Results.Created($"games/{game.Id}", game);
}
);
app.MapGet("games/{id}", async (int id, IGameRepository repo)
=>
{
var game = await repo.GetAsync(id);
if (game is null)
{
return Results.NotFound();
}
return Results.Ok(game);
}
);
app.MapGet("games", async (string? likename, IGameRepository repo)
=>
{
if (likename is null)
{
var allgames = await repo.GetAll();
return Results.Ok(allgames);
}
var matchedGames = await repo.GetGameByLikeName(likename);
return Results.Ok(matchedGames);
}
);
app.MapPut("games", async (Game game, IGameRepository repo)
=>
{
await repo.UpdateAsync(game);
return Results.Ok(game);
}
);
app.Run();
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
// Import the top-level function of express
const express = require('express');
// Creates an Express application using the top-level function
const app = express();
// Define port number as 3000
const port = 3000;
// Routes HTTP GET requests to the specified path
// "/" with the specified callback function
app.get('/', function(request, response) {
response.send('Hello, World!');
});
// Make the app listen on port 3000
app.listen(port, function() {
console.log('Server listening on http://localhost:' + port);
});
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
router.GET("/albums", getAlbums)
router.GET("/albums/:id", getAlbumByID)
router.POST("/albums", postAlbums)
router.Run("localhost:8080")
}
// album represents data about a record album.
type album struct {
ID string `json:"id"`
Title string `json:"title"`
Artist string `json:"artist"`
Price float64 `json:"price"`
}
// albums slice to seed record album data.
var albums = []album{
{ID: "1", Title: "Blue Train", Artist: "John Coltrane", Price: 56.99},
{ID: "2", Title: "Jeru", Artist: "Gerry Mulligan", Price: 17.99},
{ID: "3", Title: "Sarah Vaughan and Clifford Brown", Artist: "Sarah Vaughan", Price: 39.99},
}
// getAlbums responds with the list of all albums as JSON.
func getAlbums(c *gin.Context) {
c.IndentedJSON(http.StatusOK, albums)
}
// postAlbums adds an album from JSON received in the request body.
func postAlbums(c *gin.Context) {
var newAlbum album
// Call BindJSON to bind the received JSON to
// newAlbum.
if err := c.BindJSON(&newAlbum); err != nil {
return
}
// Add the new album to the slice.
albums = append(albums, newAlbum)
c.IndentedJSON(http.StatusCreated, newAlbum)
}
// getAlbumByID locates the album whose ID value matches the id
// parameter sent by the client, then returns that album as a response.
func getAlbumByID(c *gin.Context) {
id := c.Param("id")
// Loop through the list of albums, looking for
// an album whose ID value matches the parameter.
for _, a := range albums {
if a.ID == id {
c.IndentedJSON(http.StatusOK, a)
return
}
}
c.IndentedJSON(http.StatusNotFound, gin.H{"message": "album not found"})
}
# main.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/users/me")
async def read_user_me():
return {"user_id": "the current user"}
@app.get("/users/{user_id}")
async def read_user(user_id: str):
return {"user_id": user_id}
public class Module : NancyModule
{
public Module()
{
Get("/greet/{name}", x => {
return string.Concat("Hello ", x.name);
});
}
}
using System;
if (args.Length == 0)
{
System.Console.WriteLine("Please enter a numeric argument.");
}
namespace ViewerApp.Models
{
public class Viewer
{
public string? FirstName { get; set; }
public string? LastName { get; set; }
public string? StreetAddress { get; set; }
}
}
namespace ViewerApp.Models;
public class Viewer2
{
public string? FirstName { get; set; }
public string? LastName { get; set; }
public string? StreetAddress { get; set; }
}
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
Console.WriteLine("Daj pozytwna ocene");
await Task.Delay(2000);
List<string> list = new List<string>();
list.Add("Tej prelekcj");
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
//using System;
//using System.Collections.Generic;
//using System.Threading.Tasks;
Console.WriteLine("Daj pozytwna ocene");
await Task.Delay(2000);
List<string> list = new List<string>();
list.Add("Tej prelekcj");
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
// <autogenerated />
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using global::System.Net.Http.Json;
global using global::Microsoft.AspNetCore.Builder;
global using global::Microsoft.AspNetCore.Hosting;
global using global::Microsoft.AspNetCore.Http;
global using global::Microsoft.AspNetCore.Routing;
global using global::Microsoft.Extensions.Configuration;
global using global::Microsoft.Extensions.DependencyInjection;
global using global::Microsoft.Extensions.Hosting;
global using global::Microsoft.Extensions.Logging;
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Using Include="System.Text.Json" />
<Using Include="System.Text.Json.Serialization" />
<Using Remove="System.IO" />
<Using Include="System.Console" Static="True" />
<Using Include="System.DateTime" Alias="DT" />
</ItemGroup>
</Project>
global using ViewerApp.Models;
global using static System.Console;
global using DT = System.DateTime;
// C# 9
Func getUserInput = Console.ReadLine;
Action tellUser = (string s) => Console.WriteLine(s);
Func waitForEnter = Console.ReadLine;
tellUser("Please enter name");
var name = getUserInput();
tellUser($"Your name is {name}");
waitForEnter();
// C# 10
var getUserInput = Console.ReadLine;
var tellUser = (string s) => Console.WriteLine(s);
var waitForEnter = Console.ReadLine;
tellUser("Please enter name");
var name = getUserInput();
tellUser($"Your name is {name}");
waitForEnter();
var a1 = string () => string.Empty;
var a2 = int () => int.MaxValue;
var a3 = static void () => { };
var a4 = string? () => null;
public static void Example<T>()
{
var a5 = T () => default;
}
Func<int> f1 = [MyAttribute] () => { return 0; };
var f2 = [return: MyAttribute] () => { return 0; };
Func<int,int> f3 = ([MyAttribute] x)=> { return x; };
class MyAttribute : Attribute
{
}
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<IEmployeeService, EmployeeService>();
builder.Services.AddSingleton<IHelloWorldService, HelloWorldService>();
var app = builder.Build();
app.MapGet("/", () => "Daj Like");
app.MapGet("/quote/", async () =>
await new HttpClient().GetStringAsync
("https://ron-swanson-quotes.herokuapp.com/v2/quotes"));
app.MapPost("/employee",
(Employee e, IEmployeeService ser) =>
{
return ser.ShowEmployee(e);
});
app.MapGet("/hello",
(HttpContext context, IHelloWorldService service)
=>
{
return service.SayHello
(context.Request.Query["name"].ToString());
});
app.Run();
public class HelloWorldService : IHelloWorldService
{
public string SayHello(string user)
{
return $"Hello {user}";
}
}
public interface IHelloWorldService
{
public string SayHello(string user);
}
public record Employee(string FirstName, [Required] string LastName);
public interface IEmployeeService
{
public string ShowEmployee(Employee employee);
}
public class EmployeeService : IEmployeeService
{
public string ShowEmployee(Employee e)
{
return "We have a new employee:" +
$" {e.FirstName} {e.LastName}";
}
}