当前位置: 首页>>代码示例>>C#>>正文


C# System.Text.UTF8Encoding.GetLength方法代码示例

本文整理汇总了C#中System.Text.UTF8Encoding.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# System.Text.UTF8Encoding.GetLength方法的具体用法?C# System.Text.UTF8Encoding.GetLength怎么用?C# System.Text.UTF8Encoding.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Text.UTF8Encoding的用法示例。


在下文中一共展示了System.Text.UTF8Encoding.GetLength方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoTestLocalMessageBroadcast

        public void DoTestLocalMessageBroadcast()
        {
            Console.Write("What's your name: ");
            string name = Console.ReadLine();
            Console.Write("Which channel (0-9) do you want to use: ");
            char input = Console.ReadKey(true).KeyChar;//.ReadLine();
            while ( input != '0' && input != '1' && input != '2' && input != '3' && input != '4' && input != '5' && input != '6' && input != '7' && input != '8' && input != '9' ) {
                input = Console.ReadKey(true).KeyChar;
            }
            Console.WriteLine("\n");
            string channel = input.ToString();

            joinedDelegate = BroadcastMessagePartnerJoinedCallback;
            leftDelegate = BroadcastMessagePartnerLeftCallback;
            receivedDelegate = BroadcastMessageReceivedCallback;
            UInt32 hLocalMessageBroadcastPartner = CreateLocalMessageBroadcastPartner(
                    "BroadcastTest/channel" + channel,
                    name,
                    IntPtr.Zero,
                    Marshal.GetFunctionPointerForDelegate(joinedDelegate),
                    Marshal.GetFunctionPointerForDelegate(leftDelegate),
                    Marshal.GetFunctionPointerForDelegate(receivedDelegate)
                );

            if ( hLocalMessageBroadcastPartner > 0 ) {
                try {
                    Console.WriteLine("");
                    Console.WriteLine("Welcome " + name + "! You can talk to the others on channel " + channel + " by typing s, then your message and pressing <enter>");

                    input = Console.ReadKey(true).KeyChar;//.ReadLine();
                    while ( input != 'q' ) {
                        if ( input == 's' ) {
                            Console.Write( name + " says: ");
                            string s = Console.ReadLine();
                            byte[] stringBytes = new System.Text.UTF8Encoding().GetBytes(s);
                            BroadcastMessage( hLocalMessageBroadcastPartner, stringBytes, (UInt32)(stringBytes.GetLength(0)) );
                        }

                        input = Console.ReadKey(true).KeyChar;
                    }
                }
                finally {
                    if ( DestroyLocalMessageBroadcastPartner(hLocalMessageBroadcastPartner) ) {
                        Console.WriteLine( "SUCCESSFULLY destroyed LocalMessageBroadcast Partner" );
                    }
                    else {
                        Console.WriteLine( "FAILED to destroy LocalMessageBroadcast Partner" );
                    }
                }
            }
            else {
                Console.WriteLine( "CreateLocalMessageBroadcastPartner FAILED!!!" );
            }

            Console.WriteLine( "\nPress 'q' again to really quit..." );
            char input2 = Console.ReadKey(true).KeyChar;//.ReadLine();
            while ( input2 != 'q' ) {
            }
            //Thread.Sleep(8000);
        }
开发者ID:blausand,项目名称:Wyphon,代码行数:60,代码来源:TestLocalMessageBroadcast.cs


注:本文中的System.Text.UTF8Encoding.GetLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。