Tag Archivio per: Cast


Suppose in a Datasource there are elements with some data type and you want to convert them into types like string or double or integer, you can use the Cast() method.

Cast()

Cast() method in LINQ is used to cast/convert the data type in the existing data source to another data type. It will raise the exception if we convert them into different data types like string to integer etc.

Syntax:

input_source.Cast<datatype>()

Where:

  1. input_source can be any data source like ArrayList,List etc.
  2. data type is the type we will convert the type of the given data source.

Example 1:

Here, we will create a data source named Array List with Integer type and cast them into integer type.

So, the syntax should be:

input_source.Cast()
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;  

class Linuxhint {

  public static void Main()
    {
        //create an array list
        int[] my_arraylist={100,34,56,32,10,45};

        //display the ArrayList
        foreach (var result in my_arraylist){
Console.WriteLine(result);
        }
Console.WriteLine(«————————«);

//convert the array list collection to integer type
var final=my_arraylist.Cast();

//display
foreach (var result in final){
Console.WriteLine(result);
        }
    }
}

Output:

Explanation:

Create an array list named – my_arraylist.

Cast the my_arraylist to integer type.

Display the result using a foreach loop.

Example 2:

Here, we will create a data source named Array List with String type and cast them into string type.

So, the syntax should be:

input_source.Cast()
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;  

class Linuxhint {

  public static void Main()
    {
        //create an array list
        string[] my_arraylist={«Linuxhint»,«Java»};

        //display the ArrayList
        foreach (var result in my_arraylist){
Console.WriteLine(result);
        }
Console.WriteLine(«————————«);

//convert the array list collection to string type
var final=my_arraylist.Cast();

//display
foreach (var result in final){
Console.WriteLine(result);
        }
    }
}

Output:

Explanation:

Create an array list named – my_arraylist.

Cast the my_arraylist to string type.

Display the result using a foreach loop.

Conclusion

In this tutorial, we discussed the Cast() method. Cast() method in LINQ is used to cast/convert the data type in the existing data source to another data type. It will raise the exception if we convert them into different data types like string to integer etc. You have to specify the data types – int for integer, string for string and double for double type conversions.



Source link


Macast mpv DLNA renderer Linux

Macast is a new free and open source tool to use your computer as a DLNA media renderer, so you can cast videos, pictures and music from your phone (or another computer) to your desktop, kind of like a Chromecast. It’s available for Linux, Microsoft Windows and macOS.

The application is very easy to use, shipping with only a tray menu (without any other GUI) from where you can control it, and it uses mpv as the media player. A few days ago, Macast has added the ability to use other media players via plugins, with 3 such plugins being available right now (for IINA on macOS, pi-fm-rds for Raspberry Pi and PotPlayer for Microsoft Windows). You can also write your own plugin.

Macast Features:

  • Start / Stop casting from the tray menu
  • Set the player position and size (in a corner of the screen or centered, and various player sizes including fullscreen)
  • Optional hardware-accelerated video decode
  • Choose between 3 tray icons (default colored icon, light and dark)
  • Option to automatically start on login (not available in the tray menu, you must edit the Macast configuration, which on Linux can be found under ~/.config/Macast/macast_settings.json)
  • Set the DLNA friendly name (not available in the tray menu, you need to edit the config file)
  • Set the port used by Macast (not available in the tray menu, you need to edit the config file)
  • Support to cast videos when the DLNA client is connected to the computer’s hotspot
  • Disable or force enable a network interface (Blocked_Interfaces e Additional_Interfaces in the config file)
  • Uses mpv as the media player, with support for third-party players via plugins

You might also like: How To Cast YouTube Videos From Your Phone To Raspberry Pi Using YouTube On TV (youtube.com/tv)

To use this, launch the application, and you should see the Macast icon in your system tray. There’s no need to do anything else. Next, install a DNLA client on your phone, such as BubbleUPnP/DLNA, use it to connect to your computer, and start streaming videos, music and photos.

E.g. with BubbleUPnP/DLNA, click on the Now Playing tab at the bottom, then click the cast icon in the bottom right-hand side corner and choose the computer which is running Macast:

Then click on the Library tab and cast some media from your phone to the computer running Macast. Obviously, the computer running Macast and the phone used for casting need to be in the same network.

In case the DLNA client you’re using is unable to find Macast, make sure it’s not blocked by your firewall or router. See the Macast FAQ for more on this.

Download Macast DLNA Media Renderer

The Macast releases page has binaries for Linux (DEB packages for Debian/Ubuntu and a generic Linux binary), Microsoft Windows and macOS.

You’ll need to install mpv to be able to use Macast (unless you use a plugin to be able to use a different player). You should find it in the repositories on most Linux distributions (on Fedora it’s in the RPM Fusion repository).

Also, to get the Macast tray icon to work on Linux, make sure you have the libappindicator3 package installed (even if you use the DEB to install Macast). E.g. on Ubuntu you’ll need to install gir1.2-appindicator3-0.1 (using gir1.2-ayatanaappindicator3-0.1 might also work, but I did not try it). Also, if you’re using GNOME Shell, you’ll need an extension such as AppIndicator and KStatusNotifierItem Support (this is installed by default on Ubuntu).

You can also install Macast using PIP, via AUR on Arch Linux / Manjaro, or build it from source. See the Macast installation page for details.

You might also like: How To Cast Your GNOME Shell Desktop To A Chromecast (With Audio, Wayland / X11 Support) Using Cast to TV