C# 静态成员 `System.Net.WebRequest.Create(string)'

C# static member `System.Net.WebRequest.Create(string)'

错误 CS0176:无法使用实例引用访问静态成员“System.Net.WebRequest.Create(string)”,改为使用类型名称对其进行限定

为什么这段代码不起作用

using System;
using System.Net;
using System.Net.Http;


namespace main
{
    class firstreq
    {
        public static void Main(string[] args)
        {
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://192.168.240.1");  
            HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                HttpWebRequest webRequest2 = (HttpWebRequest)webRequest2.Create("https://192.168.240.1/getname");  
                HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();
            }  
        }
    }
}

我试过去除静电但没有用,任何解决方案都很好,谢谢

WebRequest.Create 是静态方法,因此只能在类型名称 (WebRequest) 上引用,而不能通过 class.[=14= 的实例引用]

尝试做:

 HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create("https://192.168.240.1/getname");